Custom errors with morphs
Hello,
I am trying to have custom error messages on morphs. Here is an example for a Port type.
The error message is still the original one from Arktype.
Here is the playground link:
https://arktype.io/playground?code=import%2520%257B%2520type%2520%257D%2520from%2520%2522arktype%2522%250A%250Aconst%2520Thing%2520%253D%2520type%28%2522string.numeric.parse%2520%257C%2520number%2522%29%250A%2509.to%28%25220%253Cnumber%253C%253D65535%2522%29%250A%2509.configure%28%257B%250A%2509%2509message%253A%2520%28ctx%29%2520%253D%253E%2520%257B%250A%2509%2509%2509return%2520%2522This%2520is%2520a%2520custom%2520error%2522%250A%2509%2509%257D%250A%2509%257D%29%250A%250A%252F%252F%2520const%2520out%2520%253D%2520Thing%28%2522abcd%2522%29%2520%252F%252F%2520Shows%2520custom%2520error%250Aconst%2520out%2520%253D%2520Thing%28%2522999999%2522%29%2520%252F%252F%2520Shows%2520default%2520error%250A%250A
3 Replies
Hey @ssalbdivad ! Hope everything's well
Is my issue related to this question ?
I tried the workaround you mentionned in here and tried to tweak it, but couldn't manage to get the custom error
GitHub
Unable to directly configure top-level intersection error message ...
import { type } from "arktype"; const Thing = type("string.email > 0").configure({ message: "Email is not valid", }); // standard bulleted message- config seemingly...
Hey thanks for the patience!
This is another nuance of how configuration applies to a type with an input and output.
You can work around it by passing the config to both endpoints individually if you want it to apply to both:
Playground
I'd actually be interested in revisiting the default behavior here as I think it may be reasonable for common cases like this one to propagate the config across all intermediate transforms in the Type.
If you could create a GitHub issue summarizing this case and possibly mention it on the existing issue for intersections, that would be greatly appreciated!
Done in here
GitHub
Custom error messages don't work on morph · Issue #1479 · arktype...
Report a bug I am trying to have custom error messages on morphs. Here is an example for a Port type. The error message is still the original one from Arktype. 🔎 Search Terms morph, error, configur...