Skip to content

[Feature request] ZodError with meta #5329

@ElYaiko

Description

@ElYaiko

When throwing a ZodError it would be very useful to return with it's defined meta().
So when using it with treeifyError, would return like:

const tree = z.treeifyError(result.error);
 
// =>
{
  meta: { title: "This is the title" },
  errors: [ 'Unrecognized key: "extraKey"' ],
  properties: {
    username: { errors: [ 'Invalid input: expected string, received number' ] },
    favoriteNumbers: {
      meta: { title: "Favorite numbers", description: "The favorites numbers" },
      errors: [],
      items: [
        undefined,
        {
          meta: {},
          errors: [ 'Invalid input: expected number, received string' ]
        }
      ]
    }
  }
}

Or error.issues

[
  {
    origin: "string",
    code: "too_small",
    minimum: 10,
    inclusive: true,
    path: [ "name" ],
    message: "Too small: expected string to have >=10 characters",
    meta: { title: "Name", ... }
  },
  ...
]

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