Skip to content

Bug: ParseError breaking change for error cause #4712

@agnoski

Description

@agnoski

Expected Behavior

When a ParseError is thrown by the parse function, the cause field is a ZodError.

Current Behavior

When a ParseError is thrown by the parse function, the cause field is an array of ZodIssues.

Code snippet

Pre v2.24.0:

  try {
    return schema.parse(data);
  } catch (error) {
    throw new ParseError('Failed to parse schema', { cause: error as Error });
  }

Post v2.24.0

  if (result.issues) {
    const error = new ParseError('Failed to parse schema', {
      cause: result.issues,
    });
...

Steps to Reproduce

  1. Call parser pre and post v2.24.0 with an invalid schema
  2. Check the error thrown has two different cause

Possible Solution

Keep backward compatibility by creating a ZodError from the issues or create a breaking change with version bump.

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

22.x

Packaging format used

npm

Execution logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    not-a-bugNew and existing bug reports incorrectly submitted as bug

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions