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
use bincode::ErrorKind;
use crate::{DokiError, DokiErrorKind};
use serde_json::Error;
use yggdrasil_shared::DiagnosticLevel;
impl From<Error> for DokiError {
fn from(e: Error) -> Self {
DokiError::syntax_error(e.to_string())
}
}
impl From<Box<ErrorKind>> for DokiError {
fn from(e: Box<ErrorKind>) -> Self {
let kind = match *e {
ErrorKind::Io(i) => {DokiErrorKind::IOError(i)}
ErrorKind::InvalidUtf8Encoding(e) => {DokiErrorKind::SyntaxError(e.to_string())}
ErrorKind::InvalidBoolEncoding(e) => {DokiErrorKind::SyntaxError(e.to_string())}
ErrorKind::InvalidCharEncoding => {DokiErrorKind::SyntaxError("Invalid char".to_string())}
ErrorKind::InvalidTagEncoding(e) => {DokiErrorKind::SyntaxError(e.to_string())}
ErrorKind::DeserializeAnyNotSupported => {DokiErrorKind::RuntimeError("Deserialize failed".to_string())}
ErrorKind::SizeLimit => {DokiErrorKind::RuntimeError("Size limit".to_string())}
ErrorKind::SequenceMustHaveLength => {DokiErrorKind::RuntimeError("Sequence must have length".to_string())}
ErrorKind::Custom(e) => {DokiErrorKind::RuntimeError(e)}
};
Self { kind: Box::new(kind), level: DiagnosticLevel::None, file: None, range: None }
}
}