Skip to content

[zod] Add support for extra issue keys in errors #816

@ilyichv

Description

@ilyichv

Is your feature request related to a problem? Please describe.
It would be nice to have the whole context of the issue. Let's take for example the following code in a zod's superRefine

   ctx.addIssue({
      code: 'custom',
      path: ['code'],
      minimum: serial_number_min_length,
      message: 'min_serial_number',
    });

If I take a look to the form state, under code

{
    "message": "min_serial_number",
    "type": "",
    "ref": {}
}

Loosing minimum key which may be useful for some use cases.

Describe the solution you'd like
Maybe adding a dedicated key for zod issues to the result would be the solution. Resulting in:

{
    "message": "min_serial_number",
    "type": "",
    "ref": {},
    "zodIssue": <rawIssue>
}

Describe alternatives you've considered
Currently there is no workaround except for customizing the message directly which may not be the best thing to do for some use cases. (eg. message is used as i18n key) to be translated later on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions