voa_core/error.rs
1//! Error type for voa-core
2
3use std::path::PathBuf;
4
5/// Error type for voa-core
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8 /// Identifier is illegal because it consists of the empty string
9 #[error("Identifier is empty")]
10 IdentifierIsEmpty,
11
12 /// Identifier contains illegal characters
13 #[error("Identifier contains illegal character ({0})")]
14 IdentifierIllegalChars(char),
15
16 /// Identifier is illegal
17 #[error("Identifier is illegal: {context}")]
18 IllegalIdentifier {
19 /// Context for the error
20 context: &'static str,
21 },
22
23 /// Expected a directory, but found a different entry
24 #[error("Expected a directory at {path}")]
25 ExpectedDirectory {
26 /// The path at which the error occurred.
27 path: PathBuf,
28 },
29
30 /// Expected a file, but found a different entry
31 #[error("Expected a file at {path}")]
32 ExpectedFile {
33 /// The path at which the error occurred.
34 path: PathBuf,
35 },
36
37 /// Illegal symlink found
38 #[error("Illegal symlink found at {path}: {context}")]
39 IllegalSymlink {
40 /// The path at which the error occurred.
41 path: PathBuf,
42
43 /// Context for the error
44 context: &'static str,
45 },
46
47 /// Illegal symlink target found during canonicalization
48 #[error("Illegal symlink target {path} found during canonicalization")]
49 IllegalSymlinkTarget {
50 /// The path at which the error occurred.
51 path: PathBuf,
52 },
53
54 /// Cyclic symlinks found during canonicalization
55 #[error("Cyclic symlinks found during canonicalization at {path}")]
56 CyclicSymlinks {
57 /// The path at which the error occurred.
58 path: PathBuf,
59 },
60
61 /// An I/O error occurred at a path.
62 #[error("I/O error at path {path} while {context}:\n{source}")]
63 IoPath {
64 /// The path at which the error occurred.
65 path: PathBuf,
66
67 /// The context in which the error occurred.
68 ///
69 /// This is meant to complete the sentence "I/O error at path XXX while ...".
70 context: &'static str,
71
72 /// The source error.
73 source: std::io::Error,
74 },
75
76 /// An internal error signals an inconsistency in voa-core.
77 /// Those should never happen, they signal a logic error in the implementation.
78 #[error("Internal error: {context}")]
79 InternalError {
80 /// A description of the problem
81 context: String,
82 },
83
84 /// A winnow parser for a type failed and produced and error.
85 #[error("Parser error:\n{0}")]
86 ParseError(String),
87
88 /// A write error occurred.
89 ///
90 /// Use this variant for generic errors when writing verifiers to VOA hierarchies.
91 #[error("Write error:\n{0}")]
92 WriteError(Box<dyn std::error::Error + Send + Sync>),
93}
94
95impl<'a> From<winnow::error::ParseError<&'a str, winnow::error::ContextError>> for Error {
96 /// Converts a [`winnow::error::ParseError`] into an [`Error::ParseError`].
97 fn from(value: winnow::error::ParseError<&'a str, winnow::error::ContextError>) -> Self {
98 Self::ParseError(value.to_string())
99 }
100}