Skip to content

Commit

Permalink
Add custom errors for unimplemented handlers (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
Totodore authored Oct 20, 2024
1 parent c480f09 commit 87fd00a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
20 changes: 17 additions & 3 deletions crates/socketioxide/src/handler/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ pub(crate) trait ErasedConnectHandler<A: Adapter>: Send + Sync + 'static {
#[rustversion::attr(
since(1.78),
diagnostic::on_unimplemented(
note = "Function argument is not a valid socketio extractor. \nSee `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details",
note = "Function argument is not a valid socketio extractor.
See `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details",
label = "Invalid extractor"
)
)]
Expand All @@ -167,8 +168,11 @@ pub trait FromConnectParts<A: Adapter>: Sized {
#[rustversion::attr(
since(1.78),
diagnostic::on_unimplemented(
note = "Function argument is not a valid socketio extractor. \nSee `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details",
label = "Invalid extractor"
note = "This function is not a ConnectMiddleware. Check that:
* It is a clonable sync or async `FnOnce` that returns `Result<(), E> where E: Display`.
* All its arguments are valid connect extractors.
See `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details.\n",
label = "Invalid ConnectMiddleware"
)
)]
pub trait ConnectMiddleware<A: Adapter, T>: Sized + Clone + Send + Sync + 'static {
Expand All @@ -190,6 +194,16 @@ pub trait ConnectMiddleware<A: Adapter, T>: Sized + Clone + Send + Sync + 'stati
///
/// * See the [`connect`](super::connect) module doc for more details on connect handler.
/// * See the [`extract`](crate::extract) module doc for more details on available extractors.
#[rustversion::attr(
since(1.78),
diagnostic::on_unimplemented(
note = "This function is not a ConnectHandler. Check that:
* It is a clonable sync or async `FnOnce` that returns nothing.
* All its arguments are valid connect extractors.
See `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details.\n",
label = "Invalid ConnectHandler"
)
)]
pub trait ConnectHandler<A: Adapter, T>: Sized + Clone + Send + Sync + 'static {
/// Call the handler with the given arguments.
fn call(&self, s: Arc<Socket<A>>, auth: Option<Value>);
Expand Down
10 changes: 7 additions & 3 deletions crates/socketioxide/src/handler/disconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ where
#[rustversion::attr(
since(1.78),
diagnostic::on_unimplemented(
note = "Function argument is not a valid socketio extractor. \nSee `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details",
note = "This function argument is not a valid socketio extractor.
See `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details\n",
label = "Invalid extractor"
)
)]
Expand All @@ -123,8 +124,11 @@ pub trait FromDisconnectParts<A: Adapter>: Sized {
#[rustversion::attr(
since(1.78),
diagnostic::on_unimplemented(
note = "Function argument is not a valid socketio extractor. \nSee `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details",
label = "Invalid extractor"
note = "This function is not a DisconnectHandler. Check that:
* It is a clonable sync or async `FnOnce` that returns nothing.
* All its arguments are valid disconnect extractors.
See `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details.\n",
label = "Invalid DisconnectHandler"
)
)]
pub trait DisconnectHandler<A: Adapter, T>: Send + Sync + 'static {
Expand Down
13 changes: 9 additions & 4 deletions crates/socketioxide/src/handler/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ pub(crate) trait ErasedMessageHandler<A: Adapter>: Send + Sync + 'static {
#[rustversion::attr(
since(1.78),
diagnostic::on_unimplemented(
note = "Function argument is not a valid socketio extractor. \nSee `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details",
label = "Invalid extractor"
note = "This function is not a MessageHandler. Check that:
* It is a clonable sync or async `FnOnce` that returns nothing.
* All its arguments are valid message extractors.
See `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details.\n",
label = "Invalid MessageHandler"
)
)]
pub trait MessageHandler<A: Adapter, T>: Send + Sync + 'static {
Expand Down Expand Up @@ -151,7 +154,8 @@ mod private {
#[rustversion::attr(
since(1.78),
diagnostic::on_unimplemented(
note = "Function argument is not a valid socketio extractor. \nSee `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details",
note = "This function argument is not a valid socketio extractor.
See `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details\n",
label = "Invalid extractor"
)
)]
Expand All @@ -176,7 +180,8 @@ pub trait FromMessageParts<A: Adapter>: Sized {
#[rustversion::attr(
since(1.78),
diagnostic::on_unimplemented(
note = "Function argument is not a valid socketio extractor. \nSee `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details",
note = "This function argument is not a valid socketio extractor.
See `https://docs.rs/socketioxide/latest/socketioxide/extract/index.html` for details\n",
label = "Invalid extractor"
)
)]
Expand Down

0 comments on commit 87fd00a

Please sign in to comment.