Skip to content

fix: handle unknown union variants without dropping the whole update#41

Merged
jimmy-phantom merged 2 commits into
Signalium:mainfrom
jimmy-phantom:fix/unknown-union-variant
Jun 15, 2026
Merged

fix: handle unknown union variants without dropping the whole update#41
jimmy-phantom merged 2 commits into
Signalium:mainfrom
jimmy-phantom:fix/unknown-union-variant

Conversation

@jimmy-phantom

Copy link
Copy Markdown
Collaborator

Problem

When a discriminated-union payload carries a __typename matching no known variant (commonly a server that added a variant the client schema doesn't list yet), union parsing throws. applyMutationEvent caught that throw, logged a warn, and discarded the entire entity update, including unrelated sibling fields, with nothing surfaced. The entity would silently stop updating until a known-variant payload arrived.

Change

  • Throw a distinguishable UnknownUnionVariantError at the union-discrimination site.
  • In parseData, an unknown variant on an optional field degrades to undefined and the rest of the entity applies; on a non-optional field it rethrows.
  • applyMutationEvent surfaces UnknownUnionVariantError via log.error (visible) instead of the silent warn, and still applies no partial state.
  • Initial load (applyData) and live updates (applyMutationEvent) behave identically, since the decision lives in the shared parse path.
optional union non-optional union
initial load undefined, rest applies rejects (error surfaced)
live update undefined, rest applies drop update, log.error

Tests

unknown-union-variant.test.ts covers all four cells. Full unit suite green; tsc --noEmit clean.

🤖 Generated with Claude Code

jimmy-phantom and others added 2 commits June 15, 2026 15:43
When a union payload's __typename matches no known variant (e.g. a server
that added a variant the client schema does not list yet), parsing threw and
applyMutationEvent swallowed it with a warn, discarding the entire entity
update including unrelated sibling fields.

Now an optional union field degrades to undefined and the rest of the entity
applies; a non-optional one rethrows as UnknownUnionVariantError, which
applyMutationEvent surfaces as an error (visible, not a silent warn) without
applying partial state. Initial load and live updates behave identically.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jimmy-phantom jimmy-phantom requested a review from pzuraq June 15, 2026 20:56
@jimmy-phantom jimmy-phantom merged commit 19a2e7f into Signalium:main Jun 15, 2026
1 check passed
@jimmy-phantom jimmy-phantom deleted the fix/unknown-union-variant branch June 15, 2026 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants