Skip to main content

shacl_structural_model/
error.rs

1//! Errors produced by checked constructors and standard-value decoding.
2
3use std::fmt;
4
5/// The role a rejected lexical value was supplied for.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
7pub enum LexicalRole {
8    /// A `sh:nodeKind` value, one of the six SHACL node-kind IRIs.
9    NodeKindIri,
10    /// A `sh:severity` value, a standard or application-defined absolute IRI.
11    SeverityIri,
12    /// A `sh:languageIn` member, a well-formed BCP 47 language tag.
13    LanguageTag,
14}
15
16impl fmt::Display for LexicalRole {
17    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
18        formatter.write_str(match self {
19            Self::NodeKindIri => "SHACL node kind IRI",
20            Self::SeverityIri => "SHACL severity IRI",
21            Self::LanguageTag => "BCP 47 language tag",
22        })
23    }
24}
25
26/// Errors raised by structural constructors and standard-value decoding.
27#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
28pub enum StructuralModelError {
29    /// A well-formed value is not a member of the role's closed vocabulary.
30    #[error("unknown {expected}: {lexical}")]
31    UnknownTerm {
32        /// The offending lexical value.
33        lexical: String,
34        /// The role whose vocabulary was expected.
35        expected: LexicalRole,
36    },
37    /// A value does not have the lexical syntax its role requires.
38    #[error("invalid {expected}: {lexical}")]
39    InvalidSyntax {
40        /// The offending lexical value.
41        lexical: String,
42        /// The role whose syntax was expected.
43        expected: LexicalRole,
44    },
45}