Skip to content

Commit 6990c0e

Browse files
authored
Mark DynamicPluginLoadError internal error types as source (#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()) } } } } ```
1 parent ad0af31 commit 6990c0e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

crates/bevy_dynamic_plugin/src/loader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use bevy_app::{App, CreatePlugin, Plugin};
88
#[derive(Debug, Error)]
99
pub enum DynamicPluginLoadError {
1010
#[error("cannot load library for dynamic plugin: {0}")]
11-
Library(libloading::Error),
11+
Library(#[source] libloading::Error),
1212
#[error("dynamic library does not contain a valid Bevy dynamic plugin")]
13-
Plugin(libloading::Error),
13+
Plugin(#[source] libloading::Error),
1414
}
1515

1616
/// Dynamically links a plugin at the given path. The plugin must export a function with the

0 commit comments

Comments
 (0)