webots_proto_schema/
error.rs1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum Error {
5 #[error("IO error: {0}")]
6 Io(#[from] std::io::Error),
7
8 #[error("Serialization error: {0}")]
9 Serialization(String),
10
11 #[error("Deserialization error: {0}")]
12 Deserialization(String),
13
14 #[error("Syntax error at line {line}, column {col}: {message}")]
15 Syntax {
16 line: usize,
17 col: usize,
18 message: String,
19 },
20
21 #[error("Unexpected end of input")]
22 UnexpectedEof,
23
24 #[error("Expected {expected}, found {found}")]
25 UnexpectedToken { expected: String, found: String },
26
27 #[error("Unknown version: {0}")]
28 UnknownVersion(String),
29}
30
31impl serde::ser::Error for Error {
32 fn custom<T: std::fmt::Display>(msg: T) -> Self {
33 Error::Serialization(msg.to_string())
34 }
35}
36
37impl serde::de::Error for Error {
38 fn custom<T: std::fmt::Display>(msg: T) -> Self {
39 Error::Deserialization(msg.to_string())
40 }
41}
42
43pub type Result<T> = std::result::Result<T, Error>;