dpp/errors/
serde_parsing_error.rs

1use serde_json::Error;
2use thiserror::Error;
3
4use crate::InvalidVectorSizeError;
5
6#[derive(Debug, Error, Clone, Eq, PartialEq)]
7#[error("Serde parsing error: {message:?}")]
8pub struct SerdeParsingError {
9    message: String,
10}
11
12impl SerdeParsingError {
13    pub fn new(message: impl Into<String>) -> Self {
14        Self {
15            message: message.into(),
16        }
17    }
18
19    pub fn message(&self) -> &str {
20        &self.message
21    }
22}
23
24impl From<serde_json::Error> for SerdeParsingError {
25    fn from(err: Error) -> Self {
26        let message = format!(
27            "Parsing error at line {}, column {}: {}",
28            err.line(),
29            err.column(),
30            err
31        );
32        Self::new(message)
33    }
34}
35
36impl From<anyhow::Error> for SerdeParsingError {
37    fn from(err: anyhow::Error) -> Self {
38        Self::new(err.to_string())
39    }
40}
41
42impl From<InvalidVectorSizeError> for SerdeParsingError {
43    fn from(err: InvalidVectorSizeError) -> Self {
44        Self::new(err.to_string())
45    }
46}
47
48impl From<String> for SerdeParsingError {
49    fn from(string: String) -> Self {
50        Self::new(string)
51    }
52}