Skip to content

Commit

Permalink
Fix error message display for composite errors when `overwrite = fals…
Browse files Browse the repository at this point in the history
…e` (#3046)
  • Loading branch information
gcanti authored Jun 22, 2024
1 parent f5a4175 commit 530fa9e
Show file tree
Hide file tree
Showing 9 changed files with 671 additions and 391 deletions.
25 changes: 25 additions & 0 deletions .changeset/breezy-houses-cover.md
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
}
```
Loading

0 comments on commit 530fa9e

Please sign in to comment.