doki_error/error_3rd/
for_serde.rs

1use crate::{DokiError, DokiErrorKind};
2use bincode::ErrorKind;
3use serde_json::Error;
4use yggdrasil_shared::DiagnosticLevel;
5
6impl From<Error> for DokiError {
7    fn from(e: Error) -> Self {
8        DokiError::syntax_error(e.to_string())
9    }
10}
11
12impl From<Box<ErrorKind>> for DokiError {
13    fn from(e: Box<ErrorKind>) -> Self {
14        let kind = match *e {
15            ErrorKind::Io(i) => DokiErrorKind::IOError(i),
16            ErrorKind::InvalidUtf8Encoding(e) => DokiErrorKind::SyntaxError(e.to_string()),
17            ErrorKind::InvalidBoolEncoding(e) => DokiErrorKind::SyntaxError(e.to_string()),
18            ErrorKind::InvalidCharEncoding => DokiErrorKind::SyntaxError("Invalid char".to_string()),
19            ErrorKind::InvalidTagEncoding(e) => DokiErrorKind::SyntaxError(e.to_string()),
20            ErrorKind::DeserializeAnyNotSupported => DokiErrorKind::RuntimeError("Deserialize failed".to_string()),
21            ErrorKind::SizeLimit => DokiErrorKind::RuntimeError("Size limit".to_string()),
22            ErrorKind::SequenceMustHaveLength => DokiErrorKind::RuntimeError("Sequence must have length".to_string()),
23            ErrorKind::Custom(e) => DokiErrorKind::RuntimeError(e),
24        };
25        Self { kind: Box::new(kind), level: DiagnosticLevel::None, file: None, range: None }
26    }
27}