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

Mark DynamicPluginLoadError internal error types as source #11618

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

BD103
Copy link
Member

@BD103 BD103 commented Jan 30, 2024

Objective

  • thiserror is used to derive the error type on bevy_dynamic_plugin's DynamicPluginLoadError.
  • It is an enum where each variant wraps a libloading error type.
  • thiserror supports marking this internal error types as #[source] so it can automatically fill out the Error::source method.
  • This allows other error handling libraries to get more information about the error than what Bevy by default provides. It increases interoperability between libraries.

Solution

  • Mark the internal libloading::Error of DynamicPluginLoadError with #[source].

Changelog


Here is the output from cargo-expand before and after the change.

// Before
impl Error for DynamicPluginLoadError {}
// After
impl Error for DynamicPluginLoadError {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        use thiserror::__private::AsDynError as _;

        match self {
            DynamicPluginLoadError::Library { 0: source, .. } => {
                Some(source.as_dyn_error())
            }
            DynamicPluginLoadError::Plugin { 0: source, .. } => {
                Some(source.as_dyn_error())
            }
        }
    }
}

@alice-i-cecile alice-i-cecile added the C-Usability A targeted quality-of-life change that makes Bevy easier to use label Jan 30, 2024
@alice-i-cecile alice-i-cecile added A-App Bevy apps and plugins S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Jan 30, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 30, 2024
Merged via the queue into bevyengine:main with commit 6990c0e Jan 30, 2024
26 checks passed
@BD103 BD103 deleted the dynamic_plugin/error branch January 31, 2024 01:06
tjamaan pushed a commit to tjamaan/bevy that referenced this pull request Feb 6, 2024
…ine#11618)

# Objective

- [`thiserror`](https://docs.rs/thiserror/) is used to derive the error
type on `bevy_dynamic_plugin`'s
[`DynamicPluginLoadError`](https://docs.rs/bevy_dynamic_plugin/latest/bevy_dynamic_plugin/enum.DynamicPluginLoadError.html).
- It is an enum where each variant wraps a `libloading` error type.
- `thiserror` supports marking this internal error types as `#[source]`
so it can automatically fill out the
[`Error::source`](https://doc.rust-lang.org/std/error/trait.Error.html#method.source)
method.
- This allows other error handling libraries to get more information
about the error than what Bevy by default provides. It increases
interoperability between libraries.

## Solution

- Mark the internal `libloading::Error` of `DynamicPluginLoadError` with
`#[source]`.

---

## Changelog


- Implemented the
[`Error::source`](https://doc.rust-lang.org/std/error/trait.Error.html#method.source)
method for
[`DynamicPluginLoadError`](https://docs.rs/bevy_dynamic_plugin/latest/bevy_dynamic_plugin/enum.DynamicPluginLoadError.html).

---

Here is the output from `cargo-expand` before and after the change.

```rust
// Before
impl Error for DynamicPluginLoadError {}
```

```rust
// After
impl Error for DynamicPluginLoadError {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        use thiserror::__private::AsDynError as _;

        match self {
            DynamicPluginLoadError::Library { 0: source, .. } => {
                Some(source.as_dyn_error())
            }
            DynamicPluginLoadError::Plugin { 0: source, .. } => {
                Some(source.as_dyn_error())
            }
        }
    }
}
```
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