Skip to content

Commit

Permalink
feat: add changesets
Browse files Browse the repository at this point in the history
  • Loading branch information
jmike committed Jan 16, 2024
1 parent 316e796 commit deb4639
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .changeset/popular-suns-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
'zod-validation-error': major
---

BREAKING CHANGE: Refactor `ValidationError` to accept `ErrorOptions` as second parameter.

What changed?

Previously, `ValidationError` accepted `Array<ZodIssue>` as 2nd parameter. Now, it accepts `ErrorOptions` which contains a `cause` property. If `cause` is a `ZodError` then it will extract the attached issues and expose them over `error.details`.

Why?

This change allows us to use `ValidationError` like a native JavaScript [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error). For example, we can now do:

```typescript
import { ValidationError } from 'zod-validation-error';

try {
// attempt to do something that might throw an error
} catch (err) {
throw new ValidationError('Something went deeply wrong', { cause: err });
}
```

How can you update your code?

If you are using `ValidationError` directly, then you need to update your code to pass `ErrorOptions` as a 2nd parameter.

```typescript
import { ValidationError } from 'zod-validation-error';

// before
const err = new ValidationError('Something went wrong', zodError.issues);

// after
const err = new ValidationError('Something went wrong', { cause: zodError });
```

If you were never using `ValidationError` directly, then you don't need to do anything.

0 comments on commit deb4639

Please sign in to comment.