-
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix error message display for composite errors when `overwrite = fals…
…e` (#3046)
- Loading branch information
Showing
9 changed files
with
671 additions
and
391 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,25 @@ | ||
--- | ||
"@effect/schema": patch | ||
--- | ||
|
||
Fix error message display for composite errors when `overwrite = false` | ||
|
||
This commit resolves an issue where the custom message for a struct (or tuple or union) was displayed regardless of whether the validation error was related to the entire struct or just a specific part of it. Previously, users would see the custom error message even when the error only concerned a particular field within the struct and the flag `overwrite` was not set to `true`. | ||
|
||
```ts | ||
import { Schema, TreeFormatter } from "@effect/schema" | ||
import { Either } from "effect" | ||
|
||
const schema = Schema.Struct({ | ||
a: Schema.String | ||
}).annotations({ message: () => "custom message" }) | ||
|
||
const res = Schema.decodeUnknownEither(schema)({ a: null }) | ||
if (Either.isLeft(res)) { | ||
console.log(TreeFormatter.formatErrorSync(res.left)) | ||
// before: custom message | ||
// now: { readonly a: string } | ||
// └─ ["a"] | ||
// └─ Expected string, actual null | ||
} | ||
``` |
Oops, something went wrong.