shapes_converter/shex_to_uml/
shex2uml_error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use std::io;

use prefixmap::{IriRef, PrefixMapError};
use shex_ast::{Schema, SchemaJsonError, ShapeExprLabel};
use thiserror::Error;

use super::UmlError;

#[derive(Error, Debug)]
pub enum ShEx2UmlError {
    #[error("Shape {iri} not found in schema {schema:?}")]
    ShapeNotFound { iri: IriRef, schema: Schema },

    #[error("Shape reference {sref} not found in schema {schema:?}")]
    ShapeRefNotFound {
        sref: ShapeExprLabel,
        schema: Schema,
    },

    #[error("No shapes found in schema to convert to SPARQL. Schema\n{schema:?}")]
    NoShapes { schema: Schema },

    #[error(
        "No shape found to convert to SPARQL because list of shapes is empty. Schema\n{schema:?}"
    )]
    EmptyShapes { schema: Schema },

    #[error(transparent)]
    SchemaError {
        #[from]
        err: SchemaJsonError,
    },

    #[error(transparent)]
    UmlError {
        #[from]
        err: UmlError,
    },

    #[error(transparent)]
    PrefixMapError {
        #[from]
        err: PrefixMapError,
    },

    #[error("Couldn't create temporary file to generate PlantUML content")]
    TempFileError { err: io::Error },

    #[error("Wrong cardinality: ({min},{max})")]
    WrongCardinality { min: i32, max: i32 },

    #[error("Not found environment variable: {env_name}, which should point to the folder where the external tool PlantUML is located")]
    NoPlantUMLPath { env_name: String },

    #[error("Error launching command: {command:?}\nError: {error} ")]
    PlantUMLCommandError { command: String, error: io::Error },

    #[error("Can't open generated temporary file used from PlantUML. Temporary file name: {generated_name}, error: {error:?}")]
    CantOpenGeneratedTempFile {
        generated_name: String,
        error: io::Error,
    },

    #[error("Can't create temporary file for UML content. Temporary file name: {tempfile_name}, error: {error:?}")]
    CreatingTempUMLFile {
        tempfile_name: String,
        error: io::Error,
    },

    #[error("Can't copy temporary output file to writer: {temp_name}, error: {error:?}")]
    CopyingTempFile { temp_name: String, error: io::Error },

    #[error("ShEx2Uml error: Feature not implemented: {msg}")]
    NotImplemented { msg: String },

    #[error("Not found label: {name}")]
    NotFoundLabel { name: String },
}

impl ShEx2UmlError {
    pub fn not_implemented(msg: &str) -> ShEx2UmlError {
        ShEx2UmlError::NotImplemented {
            msg: msg.to_string(),
        }
    }
}