parent
040088ccd0
commit
ba17ce8ac2
@ -0,0 +1,34 @@
|
||||
use std::io;
|
||||
use std::process::{ExitCode, Termination};
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("compile error")]
|
||||
Compile,
|
||||
#[error("runtime error")]
|
||||
Runtime,
|
||||
#[error("could not open file {path}")]
|
||||
ReadFile {
|
||||
path: String,
|
||||
#[source]
|
||||
source: io::Error,
|
||||
},
|
||||
#[error("Usage: clox [path]")]
|
||||
Usage,
|
||||
}
|
||||
|
||||
// Doesn't actually work with eyre... yet? But I'm
|
||||
// willing to give up "nice" exit status codes for
|
||||
// eyre's error handling.
|
||||
impl Termination for Error {
|
||||
fn report(self) -> ExitCode {
|
||||
ExitCode::from(match self {
|
||||
Error::Compile => 65,
|
||||
Error::Runtime => 70,
|
||||
Error::ReadFile { path, source } => 74,
|
||||
Error::Usage => 64,
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in new issue