Repository navigation
Fix unhandled promise rejections in test suite - #268
Merged
malibio merged 3 commits intoOct 13, 2025
Merged
Conversation
## Problem SharedNodeStore test suite had 966 unhandled promise rejections from PersistenceCoordinator.cancelPending() when cleanup cancelled pending operations during test teardown. ## Solution 1. Created OperationCancelledError custom error class to distinguish cancellation from real errors 2. Updated cancelPending() to use OperationCancelledError 3. Made reset() async to properly handle cancellation promises 4. Updated all test cleanup to await coordinator.reset() ## Changes - persistence-coordinator.svelte.ts: - Added OperationCancelledError class - Updated cancelPending() to reject with OperationCancelledError - Made reset() async with proper promise handling - shared-node-store.test.ts: Updated afterEach to await reset() - persistence-coordinator.test.ts: Updated afterEach to await reset() - setup.ts: Updated global afterEach to await reset() ## Results - Reduced unhandled rejections from 966 to 8 (99.2% reduction) - Remaining 8 are edge cases from operations cancelled during test execution (not cleanup) - All tests pass successfully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
## Changes Made ### 1. Fixed Remaining 8 Unhandled Rejections - **Root cause**: SharedNodeStore calls `persist()` but doesn't capture/handle promises - **Solution**: Added catch handlers for OperationCancelledError in three locations: - `setNode()` method (line 455) - `updateNode()` method (line 319) - `deleteNode()` method (line 526) - **Result**: Reduced from 8 unhandled rejections to **0** ✅ ### 2. Added Concurrent Reset Guard - Added `isResetting` flag to prevent concurrent reset() calls - Wrapped reset() logic in try/finally to ensure flag is always cleared - Prevents race conditions if reset() called multiple times ### 3. Improved Code Documentation - Enhanced comments in reset() method explaining promise capture timing - Clarified why we iterate before calling cancelPending() - Added explanation of concurrent reset guard behavior ### 4. Verified Production Code Impact - Confirmed reset() is test-only (no production usage) - Breaking change (async reset) has no production impact ## Test Results - ✅ SharedNodeStore tests: 52 passed, **0 unhandled rejections** (down from 966!) - ✅ All quality checks pass (lint, format, type check) ## Files Modified - `persistence-coordinator.svelte.ts`: Added reset guard, improved comments - `shared-node-store.ts`: Added OperationCancelledError import and catch handlers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Added comprehensive documentation to dependency-based-persistence.md explaining: - Why OperationCancelledError exists (distinguishes control flow from failures) - When operations are cancelled (superseded, test cleanup, node deletion) - How to handle cancellations in production code - Type-safe error handling with instanceof checks 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
malibio
deleted the
feature/issue-258-fix-unhandled-promise-rejections
branch
October 13, 2025 00:25
This was referenced Oct 13, 2025
malibio
added a commit
that referenced
this pull request
Feb 4, 2026
* Fix unhandled promise rejections in test suite (closes #258) ## Problem SharedNodeStore test suite had 966 unhandled promise rejections from PersistenceCoordinator.cancelPending() when cleanup cancelled pending operations during test teardown. ## Solution 1. Created OperationCancelledError custom error class to distinguish cancellation from real errors 2. Updated cancelPending() to use OperationCancelledError 3. Made reset() async to properly handle cancellation promises 4. Updated all test cleanup to await coordinator.reset() ## Changes - persistence-coordinator.svelte.ts: - Added OperationCancelledError class - Updated cancelPending() to reject with OperationCancelledError - Made reset() async with proper promise handling - shared-node-store.test.ts: Updated afterEach to await reset() - persistence-coordinator.test.ts: Updated afterEach to await reset() - setup.ts: Updated global afterEach to await reset() ## Results - Reduced unhandled rejections from 966 to 8 (99.2% reduction) - Remaining 8 are edge cases from operations cancelled during test execution (not cleanup) - All tests pass successfully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address code review feedback: Complete fix for unhandled rejections ## Changes Made ### 1. Fixed Remaining 8 Unhandled Rejections - **Root cause**: SharedNodeStore calls `persist()` but doesn't capture/handle promises - **Solution**: Added catch handlers for OperationCancelledError in three locations: - `setNode()` method (line 455) - `updateNode()` method (line 319) - `deleteNode()` method (line 526) - **Result**: Reduced from 8 unhandled rejections to **0** ✅ ### 2. Added Concurrent Reset Guard - Added `isResetting` flag to prevent concurrent reset() calls - Wrapped reset() logic in try/finally to ensure flag is always cleared - Prevents race conditions if reset() called multiple times ### 3. Improved Code Documentation - Enhanced comments in reset() method explaining promise capture timing - Clarified why we iterate before calling cancelPending() - Added explanation of concurrent reset guard behavior ### 4. Verified Production Code Impact - Confirmed reset() is test-only (no production usage) - Breaking change (async reset) has no production impact ## Test Results - ✅ SharedNodeStore tests: 52 passed, **0 unhandled rejections** (down from 966!) - ✅ All quality checks pass (lint, format, type check) ## Files Modified - `persistence-coordinator.svelte.ts`: Added reset guard, improved comments - `shared-node-store.ts`: Added OperationCancelledError import and catch handlers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Add documentation for OperationCancelledError Added comprehensive documentation to dependency-based-persistence.md explaining: - Why OperationCancelledError exists (distinguishes control flow from failures) - When operations are cancelled (superseded, test cleanup, node deletion) - How to handle cancellations in production code - Type-safe error handling with instanceof checks 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
malibio
added a commit
that referenced
this pull request
Feb 5, 2026
* Fix unhandled promise rejections in test suite (closes #258) ## Problem SharedNodeStore test suite had 966 unhandled promise rejections from PersistenceCoordinator.cancelPending() when cleanup cancelled pending operations during test teardown. ## Solution 1. Created OperationCancelledError custom error class to distinguish cancellation from real errors 2. Updated cancelPending() to use OperationCancelledError 3. Made reset() async to properly handle cancellation promises 4. Updated all test cleanup to await coordinator.reset() ## Changes - persistence-coordinator.svelte.ts: - Added OperationCancelledError class - Updated cancelPending() to reject with OperationCancelledError - Made reset() async with proper promise handling - shared-node-store.test.ts: Updated afterEach to await reset() - persistence-coordinator.test.ts: Updated afterEach to await reset() - setup.ts: Updated global afterEach to await reset() ## Results - Reduced unhandled rejections from 966 to 8 (99.2% reduction) - Remaining 8 are edge cases from operations cancelled during test execution (not cleanup) - All tests pass successfully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address code review feedback: Complete fix for unhandled rejections ## Changes Made ### 1. Fixed Remaining 8 Unhandled Rejections - **Root cause**: SharedNodeStore calls `persist()` but doesn't capture/handle promises - **Solution**: Added catch handlers for OperationCancelledError in three locations: - `setNode()` method (line 455) - `updateNode()` method (line 319) - `deleteNode()` method (line 526) - **Result**: Reduced from 8 unhandled rejections to **0** ✅ ### 2. Added Concurrent Reset Guard - Added `isResetting` flag to prevent concurrent reset() calls - Wrapped reset() logic in try/finally to ensure flag is always cleared - Prevents race conditions if reset() called multiple times ### 3. Improved Code Documentation - Enhanced comments in reset() method explaining promise capture timing - Clarified why we iterate before calling cancelPending() - Added explanation of concurrent reset guard behavior ### 4. Verified Production Code Impact - Confirmed reset() is test-only (no production usage) - Breaking change (async reset) has no production impact ## Test Results - ✅ SharedNodeStore tests: 52 passed, **0 unhandled rejections** (down from 966!) - ✅ All quality checks pass (lint, format, type check) ## Files Modified - `persistence-coordinator.svelte.ts`: Added reset guard, improved comments - `shared-node-store.ts`: Added OperationCancelledError import and catch handlers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Add documentation for OperationCancelledError Added comprehensive documentation to dependency-based-persistence.md explaining: - Why OperationCancelledError exists (distinguishes control flow from failures) - When operations are cancelled (superseded, test cleanup, node deletion) - How to handle cancellations in production code - Type-safe error handling with instanceof checks 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
malibio
added a commit
that referenced
this pull request
Feb 26, 2026
* Fix unhandled promise rejections in test suite (closes #258) ## Problem SharedNodeStore test suite had 966 unhandled promise rejections from PersistenceCoordinator.cancelPending() when cleanup cancelled pending operations during test teardown. ## Solution 1. Created OperationCancelledError custom error class to distinguish cancellation from real errors 2. Updated cancelPending() to use OperationCancelledError 3. Made reset() async to properly handle cancellation promises 4. Updated all test cleanup to await coordinator.reset() ## Changes - persistence-coordinator.svelte.ts: - Added OperationCancelledError class - Updated cancelPending() to reject with OperationCancelledError - Made reset() async with proper promise handling - shared-node-store.test.ts: Updated afterEach to await reset() - persistence-coordinator.test.ts: Updated afterEach to await reset() - setup.ts: Updated global afterEach to await reset() ## Results - Reduced unhandled rejections from 966 to 8 (99.2% reduction) - Remaining 8 are edge cases from operations cancelled during test execution (not cleanup) - All tests pass successfully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address code review feedback: Complete fix for unhandled rejections ## Changes Made ### 1. Fixed Remaining 8 Unhandled Rejections - **Root cause**: SharedNodeStore calls `persist()` but doesn't capture/handle promises - **Solution**: Added catch handlers for OperationCancelledError in three locations: - `setNode()` method (line 455) - `updateNode()` method (line 319) - `deleteNode()` method (line 526) - **Result**: Reduced from 8 unhandled rejections to **0** ✅ ### 2. Added Concurrent Reset Guard - Added `isResetting` flag to prevent concurrent reset() calls - Wrapped reset() logic in try/finally to ensure flag is always cleared - Prevents race conditions if reset() called multiple times ### 3. Improved Code Documentation - Enhanced comments in reset() method explaining promise capture timing - Clarified why we iterate before calling cancelPending() - Added explanation of concurrent reset guard behavior ### 4. Verified Production Code Impact - Confirmed reset() is test-only (no production usage) - Breaking change (async reset) has no production impact ## Test Results - ✅ SharedNodeStore tests: 52 passed, **0 unhandled rejections** (down from 966!) - ✅ All quality checks pass (lint, format, type check) ## Files Modified - `persistence-coordinator.svelte.ts`: Added reset guard, improved comments - `shared-node-store.ts`: Added OperationCancelledError import and catch handlers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Add documentation for OperationCancelledError Added comprehensive documentation to dependency-based-persistence.md explaining: - Why OperationCancelledError exists (distinguishes control flow from failures) - When operations are cancelled (superseded, test cleanup, node deletion) - How to handle cancellations in production code - Type-safe error handling with instanceof checks 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
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.
Problem
The SharedNodeStore test suite had 966 unhandled promise rejections from
PersistenceCoordinator.cancelPending()when cleanup cancelled pending operations during test teardown.Solution
Implemented a comprehensive fix following architectural guidance from the frontend-architect agent, with all code review feedback addressed:
1. Custom Error Type Pattern
OperationCancelledErrorclass - Distinguishes expected cancellation from real errorscancelPending()- Rejects withOperationCancelledErrorinstead of genericErrorinstanceofchecks to filter cancellations2. Async Reset with Promise Cleanup
reset()async - Properly handles cancellation promises and waits for all rejections to be caught3. Fixed All Unhandled Rejections
SharedNodeStoremethods (setNode,updateNode,deleteNode) calledpersist()but didn't capture/handle the returned promisesOperationCancelledErrorin all three methods4. Updated Test Cleanup
afterEachblocks to awaitcoordinator.reset()setTimeoutdelaysChanges
Core Implementation
OperationCancelledErrorclass with explicit intentcancelPending()to use custom errorreset()async with concurrent guard and proper promise handlingSharedNodeStore Fixes
OperationCancelledErrorimportsetNode()(line 455)updateNode()(line 319)deleteNode()(line 526)Test Updates
afterEachto await reset()afterEachto await reset()afterEachto await reset()Documentation
OperationCancelledErrorexplaining:Breaking Changes
PersistenceCoordinator.reset()is now asyncreset(): void→async reset(): Promise<void>coordinator.reset()calls toawait coordinator.reset()All test call sites have been updated in this PR.
Results
Testing
Architecture Notes
This implementation follows recommended patterns:
instanceofchecks enable precise control flowCloses #258
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]