about summary refs log tree commit diff
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs28
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 },
+		}
+	}
+}