-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhanced Error Reporting for Discriminated Union Tuple Schemas (#3753)
- Loading branch information
Showing
4 changed files
with
257 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
"@effect/schema": patch | ||
--- | ||
|
||
Enhanced Error Reporting for Discriminated Union Tuple Schemas, closes #3752 | ||
|
||
Previously, irrelevant error messages were generated for each member of the union. Now, when a discriminator is present in the input, only the relevant member will trigger an error. | ||
|
||
Before | ||
|
||
```ts | ||
import * as Schema from "@effect/schema/Schema" | ||
|
||
const schema = Schema.Union( | ||
Schema.Tuple(Schema.Literal("a"), Schema.String), | ||
Schema.Tuple(Schema.Literal("b"), Schema.Number) | ||
).annotations({ identifier: "MyUnion" }) | ||
|
||
console.log(Schema.decodeUnknownSync(schema)(["a", 0])) | ||
/* | ||
throws: | ||
ParseError: MyUnion | ||
├─ readonly ["a", string] | ||
│ └─ [1] | ||
│ └─ Expected string, actual 0 | ||
└─ readonly ["b", number] | ||
└─ [0] | ||
└─ Expected "b", actual "a" | ||
*/ | ||
``` | ||
|
||
After | ||
|
||
```ts | ||
import * as Schema from "@effect/schema/Schema" | ||
|
||
const schema = Schema.Union( | ||
Schema.Tuple(Schema.Literal("a"), Schema.String), | ||
Schema.Tuple(Schema.Literal("b"), Schema.Number) | ||
).annotations({ identifier: "MyUnion" }) | ||
|
||
console.log(Schema.decodeUnknownSync(schema)(["a", 0])) | ||
/* | ||
throws: | ||
ParseError: MyUnion | ||
└─ readonly ["a", string] | ||
└─ [1] | ||
└─ Expected string, actual 0 | ||
*/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters