Skip to content

fix: align TransactionUpdateResult with the native error codes - #131

Merged
SebastianStehle merged 1 commit into
y-crdt:mainfrom
jcannon98188:fix/transaction-update-result-codes
Oct 11, 2026
Merged

SebastianStehle merged 1 commit into
y-crdt:mainfrom
jcannon98188:fix/transaction-update-result-codes

Conversation

@jcannon98188

@jcannon98188 jcannon98188 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Aligns TransactionUpdateResult with the error codes returned by the native library, so a failed ApplyV1/ApplyV2 is reported as the right error.

Fixes #130

Problem

Transaction.ApplyV1 and ApplyV2 cast the native error code straight to TransactionUpdateResult. The enum was missing the end-of-stream code, so every value after IntegerOutOfBounds was off by one:

Failing input Native code Reported before Reported now
Empty or truncated update 3 (end of stream) UnexpectedValue EndOfStream
Update with an unknown content type 4 (unexpected value) InvalidJson UnexpectedValue
Oversized variable integer 2 IntegerOutOfBounds IntegerOutOfBounds

Native INVALID_JSON (5) was reported as Other, and native OTHER (6) and codes 7 to 9 matched no member at all. The native codes are the same in yrs 0.19.1 (which main builds against), 0.26 and 0.28.

Changes

TransactionUpdateResult now matches the native codes:

Member Value Change
Ok 0 unchanged
Io 1 unchanged
IntegerOutOfBounds 2 unchanged
EndOfStream 3 new
UnexpectedValue 4 was 3
InvalidJson 5 was 4
Other 6 was 5
NotEnoughMemory 7 new
TypeMismatch 8 new
Custom 9 new

The doc comment on each member now describes the case that actually produces it. UnexpectedValue also notes that it covers content the native library does not know, such as array moves written by yrs 0.26 or older, which yrs 0.27 removed.

Tests

New ApplyErrorTests, which fail on main and pass with this change:

  • an empty update reports EndOfStream
  • a truncated update reports EndOfStream
  • an oversized variable integer reports IntegerOutOfBounds
  • an update with an unknown content type reports UnexpectedValue
  • a failed update leaves the document unchanged

The full unit suite passes: 437 passed, 8 skipped, 0 failed. I ran it against a yrs.dll built from yrs 0.19.1.

Notes

  • Behaviour change: the numeric values of UnexpectedValue, InvalidJson and Other change. This only matters to code that persists or compares the raw numbers. Code that only compares against Ok, or against member names, is unaffected except that it now gets the right member. It deserves a line in the release notes.
  • Not included: YDotNet.Server/Internal/DocumentContainer.cs ignores the result of ApplyV1 when it loads a stored document, so a document that fails to decode loads as an empty one. Correct codes make that easier to diagnose but do not change it. I left it out to keep this PR to the enum.
  • Tests not covered: I only tested the v1 path. I did not test v2 malformed-input cases. In one probe, malformed v2 data made the native decoder panic, which aborts the process instead of returning a code. That is a separate upstream problem.

🤖 Generated with Claude Code

The enum was missing the end-of-stream code and shifted every following
value by one, so a failed update was reported as the wrong error. For
example, an update with an unknown content type (the native
UNEXPECTED_VALUE code, 4) was reported as InvalidJson, and an empty or
truncated update (end of stream, 3) as UnexpectedValue.

Adds EndOfStream, moves the other members to their native values and adds
the remaining native codes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@SebastianStehle
SebastianStehle merged commit 276fffd into y-crdt:main Oct 11, 2026
15 checks passed
@jcannon98188
jcannon98188 deleted the fix/transaction-update-result-codes branch October 11, 2026 16:23
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.

TransactionUpdateResult does not match the native error codes

2 participants