[Merged by Bors] - bevy_dynamic_plugin: make it possible to handle loading errors#6437
Closed
inodentry wants to merge 1 commit intobevyengine:mainfrom
inodentry:dynamic-plugin-error
Closed
[Merged by Bors] - bevy_dynamic_plugin: make it possible to handle loading errors#6437inodentry wants to merge 1 commit intobevyengine:mainfrom inodentry:dynamic-plugin-error
inodentry wants to merge 1 commit intobevyengine:mainfrom
inodentry:dynamic-plugin-error
Conversation
mockersf
approved these changes
Nov 1, 2022
djeedai
approved these changes
Nov 1, 2022
Member
Repeated |
alice-i-cecile
approved these changes
Nov 1, 2022
Member
alice-i-cecile
left a comment
There was a problem hiding this comment.
A clear improvement, even if I'm still not sold on this crate as a whole :p
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
Contributor
|
Pull request successfully merged into main. Build succeeded:
|
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Currently,
bevy_dynamic_pluginsimply 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_pluginfor loading it. I want my game to try to load it on startup, but continue without it if it cannot be loaded.Solution
dynamically_load_pluginfunction return aResult, so it can gracefully return loading errors.thiserrorto the dependencies ofbevy_dynamic_plugin, but that dependency is already used in other parts of bevy (such asbevy_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_pluginnow returnsResultinstead of panicking, to allow for error handling