Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many functions panic unnecessarily #172

Open
Veritius opened this issue May 25, 2023 · 2 comments
Open

Many functions panic unnecessarily #172

Veritius opened this issue May 25, 2023 · 2 comments

Comments

@Veritius
Copy link
Contributor

Several times across naia, functions can panic in situations where they can easily recover, such as here, here, here (this one might be debatable) and here. This is all from one file.

The Rust book (especially this section) details a pattern where instead of panicking, the function returns a Result<T,E> allowing execution to continue even if something went wrong in a way that doesn't require shutting off the entire program.

@connorcarpenter
Copy link
Member

This is definitely an issue that has been on my mind for a while. Thank you for posting this, there will probably need to be a whole release dedicated to this refactor.

@Veritius
Copy link
Contributor Author

Veritius commented May 30, 2023

Some I've noticed:

  • naia-server
    • Server
      • send_message_inner
      • entity and entity_mut
        • These could use some get_x-like alternative functions, that return a Result if the target isn't found. Bevy makes good use of these.
      • user and user_mut
        • See above.
      • room and room_mut
        • I'm not sure there's even a way to check rooms still exist.
        • Also, see above.
  • naia-client
    • Client
      • disconnect
      • send_message_inner
      • send_tick_buffer_message_inner
      • entity and entity_mut
        • Same as the server
      • despawn_entity

You can find loads of these by searching panic! with Find in Files in your IDE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants