diff --git a/.changeset/popular-suns-knock.md b/.changeset/popular-suns-knock.md deleted file mode 100644 index f661ce5..0000000 --- a/.changeset/popular-suns-knock.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -'zod-validation-error': major ---- - -BREAKING CHANGE: Refactor `ValidationError` to accept `ErrorOptions` as second parameter. - -What changed? - -Previously, `ValidationError` accepted `Array` 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. diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c7eb1c..5d9601a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,45 @@ # @causaly/zod-validation-error +## 3.0.0 + +### Major Changes + +- deb4639: BREAKING CHANGE: Refactor `ValidationError` to accept `ErrorOptions` as second parameter. + + What changed? + + Previously, `ValidationError` accepted `Array` 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. + ## 2.1.0 ### Minor Changes diff --git a/package.json b/package.json index 477a83d..6149080 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zod-validation-error", - "version": "2.1.0", + "version": "3.0.0", "description": "Wrap zod validation errors in user-friendly readable messages", "keywords": [ "zod",