Skip to main content

sbol_core/
error.rs

1//! Version-neutral read and write errors for SBOL documents.
2
3use std::path::PathBuf;
4
5use thiserror::Error;
6
7/// Errors produced while reading an SBOL document.
8#[derive(Debug, Error)]
9#[non_exhaustive]
10pub enum ReadError {
11    #[error("RDF parse error")]
12    Rdf(#[from] sbol_rdf::ParseError),
13
14    #[error("failed to read `{path}`")]
15    Io {
16        path: PathBuf,
17        #[source]
18        source: std::io::Error,
19    },
20
21    #[error(
22        "unknown RDF format for `{path}` (extension: {})",
23        extension.as_deref().unwrap_or("<none>")
24    )]
25    UnknownFormat {
26        path: PathBuf,
27        extension: Option<String>,
28    },
29}
30
31/// Lexical construction errors for the validated identity newtypes.
32///
33/// These variants reject malformed identifiers, namespaces, and hash
34/// algorithm tokens at construction time, before any version-specific
35/// document assembly runs. A versioned crate's build error wraps these
36/// so its builder surface reports a single error type.
37#[derive(Clone, Debug, PartialEq, Eq, Error)]
38pub enum BuildError {
39    #[error(
40        "invalid SBOL displayId `{0}` — must start with a letter or underscore and contain only ASCII alphanumerics or underscores"
41    )]
42    InvalidDisplayId(String),
43
44    #[error("invalid SBOL namespace `{0}` — must be an http(s) URL with no trailing slash")]
45    InvalidNamespace(String),
46
47    #[error(
48        "invalid SBOL hash algorithm `{0}` — must be one of the spec-defined tokens (SHA1, SHA256, SHA3-256, ...)"
49    )]
50    InvalidHashAlgorithm(String),
51}
52
53/// Errors produced while writing an SBOL document.
54#[derive(Debug, Error)]
55#[non_exhaustive]
56pub enum WriteError {
57    #[error("RDF write error")]
58    Rdf(#[from] sbol_rdf::WriteError),
59
60    #[error("failed to write `{path}`")]
61    Io {
62        path: PathBuf,
63        #[source]
64        source: std::io::Error,
65    },
66}