use std::io; use camino::Utf8PathBuf; #[derive(Debug, snafu::Snafu)] pub enum RuntimeError { #[snafu(display("the path was not found: {path}"))] NotFound { source: io::Error, path: Utf8PathBuf, }, #[snafu(display("io error: {path}: {source}"))] UnknownIo { source: io::Error, path: Utf8PathBuf, }, #[snafu(display("path tried to go below webroot: {path}"))] PathTooLow { path: String }, } impl RuntimeError { pub fn from_io(source: io::Error, path: Utf8PathBuf) -> Self { match source.kind() { io::ErrorKind::NotFound => RuntimeError::NotFound { source, path }, _ => RuntimeError::UnknownIo { source, path }, } } }