Skip to content

Support custom error codes #105

@jprochazk

Description

@jprochazk

Two parts:

  1. Add a code: Option<Cow<'static, str>> field to garde::Error

  2. 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 its code field in the proc macro output. (B) seems easier to implement, but those coming from validator likely expect (A).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions