about summary refs log tree commit diff
path: root/src/error.rs
blob: 56539d0ffc77d0062e9a380ff174d6a33ce24e0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 },
		}
	}
}