Skip to content

Allow boxed stderrors created from anyhow::Error to be downcast to the original type.#412

Closed
afranchuk wants to merge 1 commit into
dtolnay:masterfrom
afranchuk:master
Closed

Allow boxed stderrors created from anyhow::Error to be downcast to the original type.#412
afranchuk wants to merge 1 commit into
dtolnay:masterfrom
afranchuk:master

Conversation

@afranchuk

Copy link
Copy Markdown

Closes #379.

@dtolnay dtolnay left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the PR. I don't think this is necessarily better. This means if you take anyhow::Error with a backtrace, and convert it to Box<dyn Error>, the resulting error loses the backtrace.

@afranchuk

afranchuk commented Apr 3, 2025

Copy link
Copy Markdown
Author

That's a fair point. Maybe it would work to make the source of ErrorImpl<E> be E instead of E's source? That way you can still downcast by walking the sources. That also sort of makes sense if you squint, since you are taking some E and making a new sort of error out of it (in this case one with a backtrace attached).

Unfortunately that change may break existing code, though. But on the other hand you could also make that behavior only occur when it's converted to a boxed error to limit the extent of the change in behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conversion to Box<dyn Error> loses downcast ability

2 participants