v3.0.0
Major Changes
-
deb4639: BREAKING CHANGE: Refactor
ValidationErrorto acceptErrorOptionsas second parameter.What changed?
Previously,
ValidationErroracceptedArray<ZodIssue>as 2nd parameter. Now, it acceptsErrorOptionswhich contains acauseproperty. Ifcauseis aZodErrorthen it will extract the attached issues and expose them overerror.details.Why?
This change allows us to use
ValidationErrorlike a native JavaScript Error. For example, we can now do: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
ValidationErrordirectly, then you need to update your code to passErrorOptionsas a 2nd parameter.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
ValidationErrordirectly, then you don't need to do anything.