Added thiserror derives

This commit is contained in:
Zachary Levy
2026-04-12 12:01:34 -07:00
parent d0b792be0e
commit 2a0d9e0097
2 changed files with 12 additions and 4 deletions
+2
View File
@@ -143,6 +143,8 @@ optional = true
[dependencies.serde] [dependencies.serde]
workspace = true workspace = true
optional = true optional = true
[dependencies.thiserror]
workspace = true
[dev-dependencies.float-cmp] [dev-dependencies.float-cmp]
workspace = true workspace = true
+10 -4
View File
@@ -1,9 +1,13 @@
use thiserror::Error;
/// Indicates the transducer value is known to be impossible. /// Indicates the transducer value is known to be impossible.
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Error)]
#[error("invalid value")]
pub struct InvalidValue; pub struct InvalidValue;
/// Indicates that the encoded data is not valid for the type. /// Indicates that the encoded data is not valid for the type.
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Error)]
#[error("invalid encoding")]
pub struct InvalidEncoding; pub struct InvalidEncoding;
/// An error that it is likely impossible to recover from. This error should only be created in /// An error that it is likely impossible to recover from. This error should only be created in
/// situations where attempts to recover have already been attempted and have failed. Error handling /// situations where attempts to recover have already been attempted and have failed. Error handling
@@ -12,11 +16,13 @@ pub struct InvalidEncoding;
/// ///
/// In many systems there can be a single function for handling any critical error as a critical /// In many systems there can be a single function for handling any critical error as a critical
/// error always means everything needs to be stopped. /// error always means everything needs to be stopped.
#[derive(Copy, Clone, Eq, PartialEq, Debug)] #[derive(Copy, Clone, Eq, PartialEq, Debug, Error)]
pub enum CriticalError { pub enum CriticalError {
/// Critical communication failed and retries are either impossible or also failed. /// Critical communication failed and retries are either impossible or also failed.
#[error("critical communication failure")]
Communication, Communication,
InvalidValue(InvalidValue), #[error(transparent)]
InvalidValue(#[from] InvalidValue),
} }
/// A state of this type may mean the program has encountered an error that prevents it from continuing to run /// A state of this type may mean the program has encountered an error that prevents it from continuing to run