Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions concurrency/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license.workspace = true
spawned-rt = { workspace = true }
tracing = { workspace = true }
futures = "0.3.1"
thiserror = "2.0.12"

[dev-dependencies]
# This tokio imports are only used in tests, we should not use them in the library code.
Expand Down
28 changes: 14 additions & 14 deletions concurrency/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use std::{error::Error as StdError, fmt::Display};

#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum GenServerError {
#[error("Callback Error")]
Callback,
#[error("Initialization error")]
Initialization,
#[error("Server error")]
Server,
#[error("Unsupported Call Messages on this GenServer")]
CallMsgUnused,
#[error("Unsupported Cast Messages on this GenServer")]
CastMsgUnused,
}

Expand All @@ -21,16 +24,13 @@ impl<T> From<spawned_rt::tasks::mpsc::SendError<T>> for GenServerError {
}
}

impl Display for GenServerError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Callback => write!(f, "Callback Error"),
Self::Initialization => write!(f, "Initialization Error"),
Self::Server => write!(f, "Server Error"),
Self::CallMsgUnused => write!(f, "Unsupported Call Messages on this GenServer"),
Self::CastMsgUnused => write!(f, "Unsupported Cast Messages on this GenServer"),
}
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_error_into_std_error() {
let error: &dyn std::error::Error = &GenServerError::Callback;
assert_eq!(error.to_string(), "Callback Error");
}
}

impl StdError for GenServerError {}