shapes_converter/shex_to_html/
shex2html_error.rs

1use std::{
2    io::{self, BufWriter, IntoInnerError},
3    string::FromUtf8Error,
4};
5
6use prefixmap::{IriRef, PrefixMapError};
7use shex_ast::{Schema, SchemaJsonError, ShapeExprLabel};
8use thiserror::Error;
9
10use crate::ShEx2UmlError;
11
12use super::{HtmlShape, Name, NodeId};
13
14#[derive(Error, Debug)]
15pub enum ShEx2HtmlError {
16    #[error("Shape {iri} not found in schema {schema:?}")]
17    ShapeNotFound { iri: IriRef, schema: Schema },
18
19    #[error("No local referece for shape name: {name:?}")]
20    NoLocalRefName { name: Name },
21
22    #[error("Shape reference {sref} not found in schema {schema:?}")]
23    ShapeRefNotFound {
24        sref: ShapeExprLabel,
25        schema: Schema,
26    },
27
28    #[error("No shapes found in schema to convert to SPARQL. Schema\n{schema:?}")]
29    NoShapes { schema: Schema },
30
31    #[error(
32        "No shape found to convert to SPARQL because list of shapes is empty. Schema\n{schema:?}"
33    )]
34    EmptyShapes { schema: Schema },
35
36    #[error(transparent)]
37    SchemaError {
38        #[from]
39        err: SchemaJsonError,
40    },
41
42    #[error(transparent)]
43    PrefixMapError {
44        #[from]
45        err: PrefixMapError,
46    },
47
48    #[error(transparent)]
49    MiniNinjaError {
50        #[from]
51        err: minijinja::Error,
52    },
53
54    #[error(transparent)]
55    IOError {
56        #[from]
57        err: std::io::Error,
58    },
59
60    #[error(transparent)]
61    UTF8Error {
62        #[from]
63        err: FromUtf8Error,
64    },
65
66    #[error(transparent)]
67    IntoInnerError {
68        #[from]
69        err: IntoInnerError<BufWriter<Vec<u8>>>,
70    },
71
72    #[error(transparent)]
73    ShEx2UmlError {
74        #[from]
75        err: ShEx2UmlError,
76    },
77
78    #[error("Error creating landing page at: {name}, error: {error}")]
79    ErrorCreatingLandingPage { name: String, error: io::Error },
80
81    #[error("Error creating shapes file at: {name}, error: {error}")]
82    ErrorCreatingShapesFile { name: String, error: io::Error },
83
84    #[error("Wrong cardinality: ({min},{max})")]
85    WrongCardinality { min: i32, max: i32 },
86
87    #[error("Adding component: {component:?} to nodeId {node_id} fails because that node already contains shape: {shape:?}")]
88    AddingComponentNodeIdHasShape {
89        node_id: NodeId,
90        shape: Box<HtmlShape>,
91        component: Box<HtmlShape>,
92    },
93
94    #[error("ShEx2Uml error: Feature not implemented: {msg}")]
95    NotImplemented { msg: String },
96}
97
98impl ShEx2HtmlError {
99    pub fn not_implemented(msg: &str) -> ShEx2HtmlError {
100        ShEx2HtmlError::NotImplemented {
101            msg: msg.to_string(),
102        }
103    }
104}