Background
Currently, error state tracking is inconsistent across collection types:
- query-db-collection: Tracks
lastError and errorCount in closure variables, exposing them via utility functions (collection.utils.lastError(), collection.utils.isError(), collection.utils.errorCount()) - electric-db-collection: Has no error tracking at all - errors are thrown or logged but not stored
- Base Collection: Has
status: 'error' state but no associated error information
This creates an inconsistent developer experience where error handling differs depending on which collection type you're using.
Proposal
Make error tracking a first-class concern in the base Collection class, similar to how status is handled today.
API Changes
Add to CollectionLifecycleManager:
publicerror: Error|null=nullpublic errorCount: number=0publicmarkError(error?: Error): void{if(error){this.error=errorthis.errorCount++}this.setStatus('error')}Expose on Collection:
// Direct property access (like status)collection.error// Error | nullcollection.errorCount// number// Eventscollection.on('error',(event)=>{console.log('Error occurred:',event.error)})Benefits
- Consistency: All collection types have the same error API
- Better DX: Access
collection.error directly instead of collection.utils.lastError() - Framework integration: React, Angular, Vue adapters can reactively bind to error state
- Debugging: Errors are preserved and inspectable, not just logged
- Retry logic:
errorCount enables exponential backoff strategies
Migration Path
- Add error tracking to base Collection (non-breaking - new properties)
- Update
query-db-collection to use base error tracking instead of closure variables (internal change) - Update
electric-db-collection to pass errors to markError() instead of just throwing - Deprecate
collection.utils.lastError() in favor of collection.error (breaking in next major)
Open Questions
- Should
markError() clear the error on successful recovery, or should we have a separate clearError() method? - Should errors emit events (
collection.on('error', ...)) in addition to status events? - What should happen to
errorCount on recovery - reset to 0 or preserve for analytics? - Should we track error history (last N errors) or just the most recent?
Related
This came out of the discussion in #671 where we realized error tracking should be baked into the core Collection rather than being add-on utilities.
Background
Currently, error state tracking is inconsistent across collection types:
lastErroranderrorCountin closure variables, exposing them via utility functions (collection.utils.lastError(),collection.utils.isError(),collection.utils.errorCount())status: 'error'state but no associated error informationThis creates an inconsistent developer experience where error handling differs depending on which collection type you're using.
Proposal
Make error tracking a first-class concern in the base Collection class, similar to how
statusis handled today.API Changes
Add to
CollectionLifecycleManager:Expose on Collection:
Benefits
collection.errordirectly instead ofcollection.utils.lastError()errorCountenables exponential backoff strategiesMigration Path
query-db-collectionto use base error tracking instead of closure variables (internal change)electric-db-collectionto pass errors tomarkError()instead of just throwingcollection.utils.lastError()in favor ofcollection.error(breaking in next major)Open Questions
markError()clear the error on successful recovery, or should we have a separateclearError()method?collection.on('error', ...)) in addition to status events?errorCounton recovery - reset to 0 or preserve for analytics?Related
This came out of the discussion in #671 where we realized error tracking should be baked into the core Collection rather than being add-on utilities.