Attempt to change the way errors are created
Some checks failed
Build library & run tests / docs (push) Failing after 2m31s
Build library & run tests / build (tcp) (push) Failing after 2m41s
Build library & run tests / build (unix) (push) Failing after 2m42s

This commit is contained in:
2024-07-05 13:09:31 +02:00
parent ef1faf5bd9
commit a5c975d113
3 changed files with 25 additions and 29 deletions

View File

@@ -352,39 +352,13 @@ fn derive_protocol(input: proc_macro2::TokenStream) -> proc_macro2::TokenStream
// Create an error and result type for sending messages
let error_enum = quote! {
#[derive(::std::fmt::Debug)]
#[derive(::std::fmt::Debug, ::std::clone::Clone, ::std::fmt::Display, ::thiserror::Error)]
#vis enum #error_enum_name {
#[error("Failed to send query: {0}")]
SendError(::tokio::sync::mpsc::error::SendError<(u64, #question_enum_name)>),
#[error("Connection to sender thread closed")]
Closed,
}
impl ::std::fmt::Display for #error_enum_name {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match self {
#error_enum_name::SendError(e) => write!(f, "Failed to send query: {}", e),
#error_enum_name::Closed => write!(f, "Connection closed"),
}
}
}
impl ::std::error::Error for #error_enum_name {
fn source(&self) -> ::std::option::Option<&(dyn ::std::error::Error + 'static)> {
match self {
#error_enum_name::SendError(e) => ::std::option::Option::Some(e),
#error_enum_name::Closed => ::std::option::Option::None,
}
}
fn description(&self) -> &str {
match self {
#error_enum_name::SendError(_) => "Failed to send query",
#error_enum_name::Closed => "Connection closed",
}
}
fn cause(&self) -> ::std::option::Option<&dyn ::std::error::Error> {
match self {
#error_enum_name::SendError(e) => ::std::option::Option::Some(e),
#error_enum_name::Closed => ::std::option::Option::None,
}
}
}
};
// Create enums for the types of messages the server and client will use