question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Union Error Message

See original GitHub issue

When 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:open
  • Created 2 years ago
  • Reactions:7
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ianstormtaylorcommented, Sep 19, 2022

@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 of failure.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.

0reactions
hgwoodcommented, Oct 24, 2022

Thanks. I might try this.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found