Skip to main content

crisol_core/
error.rs

1//! The core-wide error envelope for operations that cross module boundaries.
2//!
3//! ```
4//! use crisol_core::error;
5//! ```
6
7/// A failure that does not belong to one specific subsystem.
8///
9/// Subsystems return their own error types (`DataError`, `StorageError`, `ThemeImportError`,
10/// …); this envelope is for generic helpers and for callers that need one type.
11#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
12#[non_exhaustive]
13/// # Example
14///
15/// ```
16/// use crisol_core::error::CoreError;
17/// ```
18pub enum CoreError {
19    /// An input value was rejected.
20    #[error("{0}")]
21    Invalid(&'static str),
22    /// A versioned file is newer than the code understands.
23    #[error("version {found} is newer than {latest}")]
24    UnsupportedVersion {
25        /// The version found in the file.
26        found: u32,
27        /// The newest version this build writes.
28        latest: u32,
29    },
30    /// An I/O operation failed.
31    #[error("{0}")]
32    Io(String),
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn errors_are_send_sync_and_static() {
41        fn assert_impl<T: Send + Sync + 'static>() {}
42        assert_impl::<CoreError>();
43        assert_eq!(
44            CoreError::UnsupportedVersion { found: 2, latest: 1 }.to_string(),
45            "version 2 is newer than 1"
46        );
47    }
48}