fix: add context to corrupted entity state errors#309
Open
YunchuWang wants to merge 1 commit into
Open
Conversation
… for corrupted state StateShim.getState() calls JSON.parse without error handling, producing a raw SyntaxError when entity state from the sidecar is corrupted. This is inconsistent with setState(), which wraps JSON.stringify errors with a descriptive message and preserves the cause. The fix adds a try-catch to getState() that wraps JSON.parse errors with context: 'Entity state contains invalid JSON: <details>', matching the error handling pattern used in setState(). Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves diagnostics for corrupted entity state returned from the sidecar by wrapping JSON.parse failures in StateShim.getState() with a descriptive error message while preserving the original parsing error as the cause. It also adds regression tests to ensure entity execution records failures cleanly when initial serialized state is invalid JSON.
Changes:
- Wrap
StateShim.getState()JSON parsing errors with a contextual message and preserve the original error viaErrorOptions.cause. - Add regression coverage in
entity-executor.spec.tsfor invalid initial entity state JSON, including cause preservation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/durabletask-js/src/worker/entity-executor.ts | Wraps corrupted entity state JSON parse errors with a clearer message and preserves the original error as cause. |
| packages/durabletask-js/test/entity-executor.spec.ts | Adds tests asserting failure recording and cause preservation for corrupted serialized entity state. |
Comment on lines
+622
to
+624
| it("should rollback to initial state when getState fails mid-batch", async () => { | ||
| // First operation succeeds with valid state, second operation gets corrupted state | ||
| // This tests that rollback works correctly for getState failures too |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #208
Testing
npm test -w @microsoft/durabletask-js -- --runTestsByPath test/entity-executor.spec.tsnpm run build:core