sheetport_spec/
validation.rs1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7pub struct ManifestIssue {
8 pub path: String,
9 pub message: String,
10}
11
12impl ManifestIssue {
13 pub fn new(path: impl Into<String>, message: impl Into<String>) -> Self {
14 Self {
15 path: path.into(),
16 message: message.into(),
17 }
18 }
19}
20
21impl fmt::Display for ManifestIssue {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 write!(f, "{}: {}", self.path, self.message)
24 }
25}
26
27#[derive(Debug)]
29pub struct ValidationError {
30 issues: Vec<ManifestIssue>,
31}
32
33impl ValidationError {
34 pub fn new(issues: Vec<ManifestIssue>) -> Self {
35 Self { issues }
36 }
37
38 pub fn issues(&self) -> &[ManifestIssue] {
39 &self.issues
40 }
41}
42
43impl fmt::Display for ValidationError {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 write!(
46 f,
47 "manifest validation failed with {} issue(s)",
48 self.issues.len()
49 )
50 }
51}
52
53impl std::error::Error for ValidationError {}