1use sexprs_util::{impl_error, Traceback};
2
3#[derive(Debug, Clone, PartialEq, Eq, Copy)]
4pub enum ErrorType {
5 IOError,
6 SyntectError,
7 FormatError,
8 RuntimeError,
9 FormatterError,
10 ReplError,
11}
12impl std::fmt::Display for ErrorType {
13 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
14 write!(
15 f,
16 "{}",
17 match self {
18 Self::IOError => "IOError",
19 Self::SyntectError => "SyntectError",
20 Self::FormatError => "FormatError",
21 Self::RuntimeError => "RuntimeError",
22 Self::FormatterError => "FormatterError",
23 Self::ReplError => "ReplError",
24 }
25 )
26 }
27}
28impl_error!(Error, ErrorType);
29impl From<std::io::Error> for Error {
30 fn from(e: std::io::Error) -> Self {
31 Error::new(e, ErrorType::IOError)
32 }
33}
34impl From<iocore::Error> for Error {
35 fn from(e: iocore::Error) -> Self {
36 Error::new(e, ErrorType::IOError)
37 }
38}
39
40impl From<syntect::LoadingError> for Error {
41 fn from(e: syntect::LoadingError) -> Self {
42 Error::new(e, ErrorType::SyntectError)
43 }
44}
45impl From<syntect::Error> for Error {
46 fn from(e: syntect::Error) -> Self {
47 Error::new(e, ErrorType::SyntectError)
48 }
49}
50impl From<rustyline::error::ReadlineError> for Error {
56 fn from(e: rustyline::error::ReadlineError) -> Self {
57 Error::new(e, ErrorType::ReplError)
58 }
59}
60
61impl From<sexprs_vm::Error> for Error {
62 fn from(e: sexprs_vm::Error) -> Self {
63 Error::new(e, ErrorType::RuntimeError)
64 }
65}
66
67impl From<sexprs_formatter::Error> for Error {
68 fn from(e: sexprs_formatter::Error) -> Self {
69 Error::new(e, ErrorType::FormatterError)
70 }
71}