1use crate::errors::{OakError, OakErrorKind};
4
5use core::fmt::{Display, Formatter};
6use std::error::Error;
7
8impl Error for OakError {}
9
10impl Display for OakError {
11 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
12 Display::fmt(&self.kind, f)
13 }
14}
15
16impl Error for OakErrorKind {}
17
18impl Display for OakErrorKind {
19 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
20 write!(f, "{}", self.key())?;
21 match self {
22 OakErrorKind::IoError { error, source_id } => {
23 write!(f, "({:?})", source_id)?;
24 write!(f, ": {}", error)
25 }
26 OakErrorKind::SyntaxError { message, offset, source_id } => {
27 write!(f, "{}: (at {:?}:{})", message, source_id, offset)
28 }
29 OakErrorKind::UnexpectedCharacter { character, offset, source_id } => {
30 write!(f, "unexpected character '{}' at {:?}:{}", character, source_id, offset)
31 }
32 OakErrorKind::UnexpectedToken { token, offset, source_id } => {
33 write!(f, "unexpected token '{}' at {:?}:{}", token, source_id, offset)
34 }
35 OakErrorKind::UnexpectedEof { offset, source_id } => {
36 write!(f, "unexpected end of file at {:?}:{}", source_id, offset)
37 }
38 OakErrorKind::CustomError { message } => write!(f, "{}", message),
39 OakErrorKind::InvalidTheme { message } => write!(f, "{}", message),
40 OakErrorKind::UnsupportedFormat { format } => write!(f, "unsupported format: {}", format),
41 OakErrorKind::ColorParseError { color } => write!(f, "invalid color: {}", color),
42 OakErrorKind::FormatError { message } => write!(f, "{}", message),
43 OakErrorKind::SemanticError { message } => write!(f, "{}", message),
44 OakErrorKind::ProtocolError { message } => write!(f, "{}", message),
45 OakErrorKind::ExpectedToken { expected, offset, source_id } => {
46 write!(f, "expected token '{}' at {:?}:{}", expected, source_id, offset)
47 }
48 OakErrorKind::ExpectedName { name_kind, offset, source_id } => {
49 write!(f, "expected {} at {:?}:{}", name_kind, source_id, offset)
50 }
51 OakErrorKind::TrailingCommaNotAllowed { offset, source_id } => {
52 write!(f, "trailing comma not allowed at {:?}:{}", source_id, offset)
53 }
54 OakErrorKind::TestFailure { path, expected, actual } => {
55 write!(f, "test failure in {:?}: expected {}, found {}", path, expected, actual)
56 }
57 OakErrorKind::TestRegenerated { path } => {
58 write!(f, "test regenerated: {:?}", path)
59 }
60 OakErrorKind::SerdeError { message } => write!(f, "serde error: {}", message),
61 OakErrorKind::DeserializeError { message } => write!(f, "deserialization error: {}", message),
62 OakErrorKind::XmlError { message } => write!(f, "XML error: {}", message),
63 OakErrorKind::ZipError { message } => write!(f, "zip error: {}", message),
64 OakErrorKind::ParseError { message } => write!(f, "parse error: {}", message),
65 OakErrorKind::InternalError { message } => write!(f, "internal error: {}", message),
66 }
67 }
68}