Skip to content

fix(schema): give predicate errors an explicit expected default - #1668

Merged
ssalbdivad merged 2 commits into
mainfrom
fix-reject-union-expected
Sep 30, 2026
Merged

ssalbdivad merged 2 commits into
mainfrom
fix-reject-union-expected

Conversation

@ssalbdivad

@ssalbdivad ssalbdivad commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #1667

ctx.reject without `expected` creates a predicate error with no
`predicate` in its context. Union error aggregation reads `expected`
from each branch, which fell back to the default description and
dereferenced `predicate.name`, throwing a TypeError.

Fixes #1667

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — verified the one-line crash fix and the accompanying regression test.

  • Missing-predicate guard: node.predicate?.name || "an anonymous predicate" in the predicate description default (ark/schema/predicate.ts:68) now tolerates the error-context form that implementNode passes here, resolving the TypeError from #1667.
  • Regression test: narrow.test.ts:258 pins the non-discriminated-union message. I reverted predicate.ts to the base and confirmed it reproduces TypeError: Cannot read properties of undefined (reading 'name'), then passes with the fix.

Full suite (pnpm test) passes at 1752 tests; eslint and prettier --check are clean on both files. The fallback message drops a custom ctx.reject({ problem }) in favor of the generic predicate description — that is the pre-existing union expected-aggregation behavior, and the snapshot intentionally records it.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

The generic expected default in implementNode falls back to calling the
node's description writer with the error context. That only works when
the context mirrors the node's inner, but predicate error contexts never
carry `predicate` (it is optional in Predicate.ErrorContext and nothing
sets it), and those from ctx.reject have no `description` either.

Rather than making the node's description tolerate a missing predicate,
predicate now defines `expected` over its actual error context, so the
node-typed description stays sound.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ssalbdivad ssalbdivad changed the title fix(schema): handle missing predicate in default predicate description fix(schema): give predicate errors an explicit expected default Sep 30, 2026
@ssalbdivad
ssalbdivad merged commit e6a8b3f into main Sep 30, 2026
6 checks passed
@ssalbdivad
ssalbdivad deleted the fix-reject-union-expected branch September 30, 2026 19:45
ssalbdivad added a commit that referenced this pull request Sep 30, 2026
Bumps all publishable packages and documents the changes merged since 2.2.5:

- add ArkErrors.message, aliasing summary (#1671)
- fix a TypeError when ctx.reject without `expected` fails in an
  undiscriminated union (#1668, fixes #1667)
- preserve narrows on piped union branches through an intersection
  (#1658, fixes #1608, @ShuviSchwarze)
- format times in Date descriptions independent of the default locale
  (#1603, fixes #1494, @WolfieLeader)

#1603 changes the text of Date error messages in 24-hour locales, e.g.
"14:30, January 15, 2023" is now "2:30 PM, January 15, 2023".

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done (merged or closed)

Development

Successfully merging this pull request may close these issues.

ctx.reject without expected in a non-discriminated union branch throws TypeError reading predicate.name

1 participant