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

[Merged by Bors] - bevy_dynamic_plugin: make it possible to handle loading errors #6437

Closed
wants to merge 1 commit into from
Closed

[Merged by Bors] - bevy_dynamic_plugin: make it possible to handle loading errors #6437

wants to merge 1 commit into from

Conversation

inodentry
Copy link
Contributor

Objective

Currently, bevy_dynamic_plugin simply panics on error. This makes it impossible to handle failures in applications that use this feature.

For example, I'd like to build an optional expansion for my game, that may not be distributed to all users. I want to use bevy_dynamic_plugin for loading it. I want my game to try to load it on startup, but continue without it if it cannot be loaded.

Solution

  • Make the dynamically_load_plugin function return a Result, so it can gracefully return loading errors.
  • Create an error enum type, to provide useful information about the kind of error. This adds thiserror to the dependencies of bevy_dynamic_plugin, but that dependency is already used in other parts of bevy (such as bevy_asset), so not a big deal.

I chose not to change the behavior of the builder method in the App extension trait. I kept it as panicking. There is no clean way (that I'm aware of) to make a builder-style API that has fallible methods. So it is either a panic or a warning. I feel the panic is more appropriate.


Changelog

Changed

  • bevy_dynamic_plugin::dynamically_load_plugin now returns Result instead of panicking, to allow for error handling

@inodentry inodentry added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-App Bevy apps and plugins labels Nov 1, 2022
@alice-i-cecile
Copy link
Member

There is no clean way (that I'm aware of) to make a builder-style API that has fallible methods

Repeated ? chaining works pretty well! I'm fine to leave that for another PR though; it's more controversial and involved.

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A clear improvement, even if I'm still not sold on this crate as a whole :p

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Nov 1, 2022
@alice-i-cecile
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Nov 1, 2022
# Objective

Currently, `bevy_dynamic_plugin` simply panics on error. This makes it impossible to handle failures in applications that use this feature.

For example, I'd like to build an optional expansion for my game, that may not be distributed to all users. I want to use `bevy_dynamic_plugin` for loading it. I want my game to try to load it on startup, but continue without it if it cannot be loaded.

## Solution

 - Make the `dynamically_load_plugin` function return a `Result`, so it can gracefully return loading errors.
 - Create an error enum type, to provide useful information about the kind of error. This adds `thiserror` to the dependencies of `bevy_dynamic_plugin`, but that dependency is already used in other parts of bevy (such as `bevy_asset`), so not a big deal.
 
 I chose not to change the behavior of the builder method in the App extension trait. I kept it as panicking. There is no clean way (that I'm aware of) to make a builder-style API that has fallible methods. So it is either a panic or a warning. I feel the panic is more appropriate.

---

## Changelog

### Changed
 - `bevy_dynamic_plugin::dynamically_load_plugin` now returns `Result` instead of panicking, to allow for error handling
@bors bors bot changed the title bevy_dynamic_plugin: make it possible to handle loading errors [Merged by Bors] - bevy_dynamic_plugin: make it possible to handle loading errors Nov 1, 2022
@bors bors bot closed this Nov 1, 2022
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
…ngine#6437)

# Objective

Currently, `bevy_dynamic_plugin` simply panics on error. This makes it impossible to handle failures in applications that use this feature.

For example, I'd like to build an optional expansion for my game, that may not be distributed to all users. I want to use `bevy_dynamic_plugin` for loading it. I want my game to try to load it on startup, but continue without it if it cannot be loaded.

## Solution

 - Make the `dynamically_load_plugin` function return a `Result`, so it can gracefully return loading errors.
 - Create an error enum type, to provide useful information about the kind of error. This adds `thiserror` to the dependencies of `bevy_dynamic_plugin`, but that dependency is already used in other parts of bevy (such as `bevy_asset`), so not a big deal.
 
 I chose not to change the behavior of the builder method in the App extension trait. I kept it as panicking. There is no clean way (that I'm aware of) to make a builder-style API that has fallible methods. So it is either a panic or a warning. I feel the panic is more appropriate.

---

## Changelog

### Changed
 - `bevy_dynamic_plugin::dynamically_load_plugin` now returns `Result` instead of panicking, to allow for error handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-App Bevy apps and plugins C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants