zod-validation-error
Advanced tools
Changelog
3.3.0
66f5b5d: Match ZodError
via heuristics instead of relying on instanceof
.
Why? Because we want to ensure that zod-validation-error works smoothly even when multiple versions of zod have been installed in the same project.
Changelog
3.2.0
fromError
API which is a less strict version of fromZodError
fromZodError
and throw dev-friendly TypeError
suggesting usage of fromError
insteadChangelog
3.0.3
Changelog
3.0.2
Changelog
3.0.1
Changelog
3.0.0
deb4639: 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. 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 ValidationError
directly, then you need to update your code to pass ErrorOptions
as 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 ValidationError
directly, then you don't need to do anything.