diff options
author | gennyble <gen@nyble.dev> | 2024-02-22 04:12:40 -0600 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2024-02-22 04:12:40 -0600 |
commit | 23876c5420c20292966367659708a200c8668f96 (patch) | |
tree | 0c8b0fd06d622cb16511a6e7610511986a9d9d31 /src/error.rs | |
parent | c4eff133ed2a2c3deb8fad322a430b3263b6e6ab (diff) | |
download | awake-23876c5420c20292966367659708a200c8668f96.tar.gz awake-23876c5420c20292966367659708a200c8668f96.zip |
Minimum viable
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..56539d0 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,28 @@ +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 }, + } + } +} |