-
Notifications
You must be signed in to change notification settings - Fork 29
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
Support custom error codes #105
Comments
I think either (A) or (B) are good to go, as long as different rules can set different codes, it doesn't matter that much the syntax that's more similar to It must support both with and without code tho, so maybe the (A) its easier to understand in those cases. btw, https://github.com/TedDriggs/darling might help with attribute parsing |
Based on: Would there be a way to also dynamically capture the criteria? The code is helpful, but in the real world it you really need to know what I'm spitballing, but perhaps something along the lines of Custom codes/messages is the one feature that is preventing be being able to migrate my validation to garde - I'd be really happy to see this! |
There's an issue open for serializing constraints, which are rules + their inputs: |
Two parts:
Add a
code: Option<Cow<'static, str>>
field togarde::Error
Add a way to set the code for a specific rule via the proc macro.
The unresolved question here is syntax:
Option A:
#[garde(length(min = 1, code = "custom_error_code"))]
Option B:
#[garde(code("custom_error_code", length(min = 1)))]
(A) would require some hacks to "intercept" the
code
value during parsing. Both would work by intercepting the error returned by a rule and set itscode
field in the proc macro output. (B) seems easier to implement, but those coming fromvalidator
likely expect (A).The text was updated successfully, but these errors were encountered: