Union Error Message
See original GitHub issueWhen one passes in data that satisfies no conditions for a union
the error message is rather unhelpful. Consider the following, where we neglect to provide a target
field on the either object({})
provided to union([])
.
const { assert, object, number, string } = window.Superstruct
const { union } = window.Superstruct;
const Validation = union([
object({ documentID: string() }),
object({ formID: string() }),
]);
const data = {
target: 'DOCUMENT',
documentID: 'identifier',
}
The resulting error message looks as follows, to be contrasted with the error message against a raw object({})
:
Expected the value to satisfy a union of `object | object`, but received: [object Object]
At path: target -- Expected a value of type `never`, but received: `\"DOCUMENT\"`
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Union Error Message - Microsoft Q&A
Hi,. I am trying to UNION 2 tables below to create the one table but when running it, I get the following error...
Read more >SQL Server Error Messages - Msg 104
This error happens when you are using the UNION operator when combining the results of multiple SELECT statements and you also specified an...
Read more >Handle errors with union - Stack Overflow
Does it look weird in C? @4386427 Well, I will be relying on the const enum type type value to tell if the...
Read more >How to resolve Union error of different data types?
There are a couple of possible sources of error that I can think of: 1) There's a full data type mismatch e.g. trying...
Read more >GraphQL Error Handling with Union Types - Episode #30
If you've been working with GraphQL, and handling errors, you no doubt have had to do some fuzzy matching on errors to get...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@hgwood thanks for the helpful write up! I like that idea with the extra context of the first failure—I believe it should use
failure.path
instead offailure.key
in case it’s deeply nested. If you wanted to pull request that would be great!For Example 2 it would be interesting to know what TypeScript does without the interfaces defined, so that it can’t just say
A | B
since Superstruct doesn’t know those nicer names usually.Thanks. I might try this.