Skip to content

Support optional Error::source (#426) #459

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tyranron
Copy link
Collaborator

Resolves #426

Synopsis

See #426 (comment):

I’d like to be able to use derive_more with optional sources, like:

#[derive(derive_more::Error, derive_more::Display, Debug)]
#[display("it’s an error")]
struct MyErr {
    source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
}

Solution

The way, the thiserror it does, is by checking the type name to contain Option. Relying on type could be fragile, as the call site could introduce its own type named Option in the scope where macro is called. Ideally, we need to aid this case with type machinery.

Checklist

  • Documentation is updated
  • Tests are added/updated
  • CHANGELOG entry is added

@tyranron tyranron added this to the 2.1.0 milestone Apr 24, 2025
@tyranron tyranron self-assigned this Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional source for Error
1 participant