Introduce invalid data error macro - #2928
Open
xanderbailey wants to merge 1 commit into
Open
Conversation
xanderbailey
force-pushed
the
xb/invalid_data_macro
branch
from
July 30, 2026 14:28
7a4473f to
b4c444d
Compare
xanderbailey
marked this pull request as ready for review
July 30, 2026 14:29
Contributor
Author
|
Not sure what folks think about this change but I personally think it improves readability. |
anoopj
approved these changes
Jul 31, 2026
| /// // Attaching a source error | ||
| /// let n: i32 = s.parse().map_err(|e| invalid_data!("not an int: {s}").with_source(e))?; | ||
| /// ``` | ||
| macro_rules! invalid_data { |
Member
There was a problem hiding this comment.
Just one design thought: the expr arm accepts any expression, so if somone writes invalid_data!(format!(...)) (out of habit), we will double allocate. Not worth guarding against though.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Today we construct
DataInvalidlike so: which ends up being very verbose in my opinionWhat changes are included in this PR?
Introduce
invalid_data!macro as a shorthand for this error.The error above becomes:
Are these changes tested?
AI Disclosure
Claude wrote the script to do this migration but I have reviewed manually.