valibot: Transformation action now executes after failed schema check
After upgrading to 0.28.1 from 0.20.1 the transformation action executes after a failed schema check. This should never happen and is a bug.
const schema = transform(
string('Invalid string', [regex(/^[0-9]+ (milliseconds?|seconds?|minutes?|hours?|days?)/)]),
() => {
throw new Error('This error should not happen for invalid input')
}
}
// This will throw my error instead of a valibot error.
parse(schema, 'INVALID')
About this issue
- Original URL
- State: closed
- Created 5 months ago
- Comments: 41 (26 by maintainers)
Commits related to this issue
- Change implementation of transform method #436 — committed to fabian-hiller/valibot by fabian-hiller 4 months ago
I had a call with @Demivan and thought about the current behavior of
transform
. I agree, and suspect that most users expect it to be executed only when the input has no issues. So I plan to change the implementation oftransform
. For now, I don’t plan to make this behavior configurable, because I don’t want to add configurations that aren’t needed. But I am open to feedback on this and may add it later.My apologies then. I was confused with the current solution that Fabian introduced and your proposal I guess. I actually like your
customPartial
proposal the best.And we could create a TS type that will filters out everything except the relevant fields inside the input.
Yes, feel free to reach out on Discord (fabianhiller) or express your pain points and ideas here in the comments.
I don’t have an example off hand, but unpredictable behavior is why bugs exist. And this is a validation library, after all.
That makes a lot of sense. I would just add that Valibot is also the best option for serverless as well. We use it to do server-side validation. I guess that’s why I’m prioritizing predictability.
Let me think about it some more. I’ll have more time tomorrow or the day after.