superstruct
superstruct copied to clipboard
Include constraint arguments in errors
When using refinements, I have noticed there is no way to get the arguments passed to it in the errors meaning it's impossible to recreate the StructError.message
that is returned.
const confirmation = object({
email: size(string(), 3, 254)
});
Should this fail, the error includes the min
and max
thresholds which is critical to the clarity of the error.
`string` expected with a length between `3` and `254` but received one with a size of 2
Being as it is not recommended to rely on these errors, I think it would be good for these to be included so they can be used in creating errors of our own.
Hey @nblackburn I see what you mean, I think I'm okay with that, I'm unsure exactly how typing the errors would work, but that might be alright for now.
Would you be down to submit a PR that adds that to size
as well as min/max
? They can return an object { message, min, max }
and { message, threshold }
instead of the current message string.
+1