sdf_metadata/util/
validation_error.rs

1use crate::util::config_error::INDENT;
2
3use super::config_error::ConfigError;
4
5#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
6pub struct ValidationError {
7    pub msg: String,
8}
9
10impl ValidationError {
11    pub fn new(msg: &str) -> Self {
12        Self {
13            msg: msg.to_string(),
14        }
15    }
16
17    pub fn add_context(&self, context: &str) -> Self {
18        Self {
19            msg: format!("{} {}", context, self.msg),
20        }
21    }
22}
23
24impl ConfigError for ValidationError {
25    fn readable(&self, indent: usize) -> String {
26        format!("{}{}\n", INDENT.repeat(indent), self.msg)
27    }
28}