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

feat: Support display for WrappedError #8

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

duskmoon314
Copy link
Contributor

This commit supports display attributes for wrapped errors. Users can now customize the display of wrapped errors by providing a string literal or a format string with source as the argument.

Partially solves #7

This commit supports display attributes for wrapped error.
Now users can customize the display of wrapped error by providing a
string literal or a format string with `source` as the argument.

Partially solves mcmah309#7
@duskmoon314
Copy link
Contributor Author

This PR is more like a POC. It may be better to avoid providing source after the formatting string.

@mcmah309
Copy link
Owner

mcmah309 commented Oct 17, 2024

Good work! I'm fine with this implementation. It's more explicit and allows for just using a field on source if desired.

In the future we could support

error_set! {
        Y = {
            #[display("Y io error: {}")] // or "Y io error: {0}"
            IoError(std::io::Error),
        };
    }

Without the need to specify source. We'd just need to parse the string if is_str_literal is true, to determine if format! is needed, using something like a try with https://github.com/A1-Triard/dyn-fmt, since format! does not support unused arguments.

@mcmah309 mcmah309 merged commit c942fcc into mcmah309:master Oct 17, 2024
1 check passed
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.

2 participants