Skip to content

Commit

Permalink
Improve client event error messages and document the logging (#322)
Browse files Browse the repository at this point in the history
* Remove explicit typing
* Include event name in the error
* Add troubleshooting section to the docs

Co-authored-by: UkoeHB <[email protected]>
  • Loading branch information
Shatur and UkoeHB authored Sep 3, 2024
1 parent 3d48f5a commit a773fa2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/core/event_registry/client_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ unsafe fn send<E: Event>(
for event in reader.read(events.deref()) {
let mut cursor = Default::default();
event_data
.serialize::<E>(ctx, event, &mut cursor)
.serialize(ctx, event, &mut cursor)
.expect("client event should be serializable");

trace!("sending event `{}`", any::type_name::<E>());
Expand All @@ -390,15 +390,18 @@ unsafe fn receive<E: Event>(
let events: &mut Events<FromClient<E>> = events.deref_mut();
for (client_id, message) in server.receive(event_data.channel_id) {
let mut cursor = Cursor::new(&*message);
match event_data.deserialize::<E>(ctx, &mut cursor) {
match event_data.deserialize(ctx, &mut cursor) {
Ok(event) => {
trace!(
"applying event `{}` from `{client_id:?}`",
any::type_name::<E>()
);
events.send(FromClient { client_id, event });
}
Err(e) => debug!("unable to deserialize event from {client_id:?}: {e}"),
Err(e) => debug!(
"ignoring event `{}` from {client_id:?} that failed to deserialize: {e}",
any::type_name::<E>()
),
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,23 @@ To reduce packet size there are the following limits per replication update:
- Up to [`u16::MAX`] entities that have changed components with up to [`u16::MAX`] bytes of component data.
- Up to [`u16::MAX`] entities that have removed components with up to [`u16::MAX`] bytes of component data.
- Up to [`u16::MAX`] entities that were despawned.
## Troubleshooting
If you face any issue, try to enable logging to see what is going on.
To enable logging, you can temporarely set `RUST_LOG` environment variable to `bevy_replicon=debug`
(or `bevy_replicon=trace` for more noisy output) like this:
```bash
RUST_LOG=bevy_replicon=debug cargo run
```
The exact method depends on the OS shell.
Alternatively you can configure [`LogPlugin`](bevy::log::LogPlugin) to make it permanent.
For deserialization errors on client we use `error` level which should be visible by default.
But on server we use `debug` for it to avoid flooding server logs with errors caused by clients.
*/
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

Expand Down

0 comments on commit a773fa2

Please sign in to comment.