shex_validation/
validator_error.rs1use std::fmt::Display;
2
3use prefixmap::PrefixMapError;
4use rbe::RbeError;
5use shex_ast::ir::preds::Preds;
6use shex_ast::ir::shape_expr::ShapeExpr;
7use shex_ast::{ir::shape_label::ShapeLabel, Node, Pred, ShapeExprLabel, ShapeLabelIdx};
8use srdf::Object;
9use thiserror::Error;
10
11use crate::Reasons;
12
13#[derive(Error, Debug, Clone)]
14pub enum ValidatorError {
15 #[error("Negation cycle error: {neg_cycles:?}")]
16 NegCycleError {
17 neg_cycles: Vec<Vec<(String, String, Vec<String>)>>,
18 },
19
20 #[error("SRDF Error: {error}")]
21 SRDFError { error: String },
22
23 #[error("Not found shape label {shape}")]
24 NotFoundShapeLabel { shape: ShapeLabel },
25
26 #[error("Not found shape label with index {idx}")]
27 NotFoundShapeLabelWithIndex { idx: ShapeLabelIdx },
28
29 #[error("Error converting object to iri: {object}")]
30 ConversionObjectIri { object: Object },
31
32 #[error("Compiling schema: {error}")]
33 SchemaIRError { error: String },
34
35 #[error("Shapemap error: {error}")]
36 ShapeMapError { error: String },
37
38 #[error("Failed regular expression")]
39 RbeFailed(),
40
41 #[error("Closed shape but found properties {remainder:?} which are not part of shape declared properties: {declared:?}")]
42 ClosedShapeWithRemainderPreds { remainder: Preds, declared: Preds },
43
44 #[error(transparent)]
45 RbeError(#[from] RbeError<Pred, Node, ShapeLabelIdx>),
46
47 #[error(transparent)]
48 PrefixMapError(#[from] PrefixMapError),
49
50 #[error("ShapeLabel not found {shape_label:?}: {error}")]
51 ShapeLabelNotFoundError {
52 shape_label: ShapeExprLabel,
53 error: String,
54 },
55
56 #[error("And error: shape expression {shape_expr} failed for node {node}: {errors}")]
57 ShapeAndError {
58 shape_expr: ShapeExpr,
59 node: Node,
60 errors: ValidatorErrors,
61 },
62
63 #[error("OR error: shape expression {shape_expr} failed for node {node}: all branches failed")]
64 ShapeOrError {
65 shape_expr: ShapeExpr,
66 node: Node,
67 errors: Vec<(ShapeExpr, ValidatorErrors)>,
68 },
69
70 #[error(
71 "Shape Not error: failed for node {node} because it passed {shape_expr} with {reasons}"
72 )]
73 ShapeNotError {
74 shape_expr: ShapeExpr,
75 node: Node,
76 reasons: Reasons,
77 },
78
79 #[error("Error reading config file from path {path}: {error}")]
80 ValidatorConfigFromPathError { path: String, error: String },
81
82 #[error("Error reading config file from path {path}: {error}")]
83 ValidatorConfigTomlError { path: String, error: String },
84
85 #[error("Adding non conformant {node}@{label} error: {error}")]
86 AddingNonConformantError {
87 node: String,
88 label: String,
89 error: String,
90 },
91
92 #[error("Adding conformant {node}@{label} error: {error}")]
93 AddingConformantError {
94 node: String,
95 label: String,
96 error: String,
97 },
98
99 #[error("Adding pending {node}@{label} error: {error}")]
100 AddingPendingError {
101 node: String,
102 label: String,
103 error: String,
104 },
105
106 #[error("Shape not found for index {idx}")]
107 ShapeExprNotFound { idx: ShapeLabelIdx },
108}
109
110#[derive(Debug, Clone)]
111pub struct ValidatorErrors {
112 errs: Vec<ValidatorError>,
113}
114
115impl ValidatorErrors {
116 pub fn new(errs: Vec<ValidatorError>) -> ValidatorErrors {
117 ValidatorErrors { errs }
118 }
119}
120
121impl Display for ValidatorErrors {
122 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
123 for err in self.errs.iter() {
124 writeln!(f, " {err}")?;
125 }
126 Ok(())
127 }
128}