Ensures message is sent w/ sync-done & error events#1358
Ensures message is sent w/ sync-done & error events#1358DougReeder wants to merge 2 commits intomasterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR standardizes emitted event payloads to match the documented/public API expectations: sync-done should always provide a { completed: boolean } result object, and error should always provide an Error instance.
Changes:
- Ensure Dropbox sync failure path emits
sync-donewith{ completed: false }. - Ensure IndexedDB database-level errors emit an
Errorobject instead of a non-error/empty payload.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/indexeddb.ts |
Updates IndexedDB db.onerror handler to emit an Error instance for error events. |
src/dropbox.ts |
Updates Dropbox sync hook to emit sync-done with { completed: false } on fetchDelta failure. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/indexeddb.ts
Outdated
| (db as any).onerror = evt => { | ||
| remoteStorage._emit('error', new Error(`database error: ${evt?.type}`)); |
There was a problem hiding this comment.
The emitted Error message here is likely not very actionable: for IndexedDB onerror events, evt.type will usually just be "error". Consider extracting the underlying IndexedDB error (e.g., from evt.target.error / evt.target.error.message when available) so consumers get a meaningful error message while still receiving an Error instance.
| (db as any).onerror = evt => { | |
| remoteStorage._emit('error', new Error(`database error: ${evt?.type}`)); | |
| (db as any).onerror = (evt: any) => { | |
| const idbError = evt && evt.target && (evt.target as any).error; | |
| const detail = | |
| (idbError && (idbError.message || String(idbError))) || | |
| (evt && evt.type) || | |
| 'unknown'; | |
| remoteStorage._emit('error', new Error(`database error: ${detail}`)); |
There was a problem hiding this comment.
This is a good idea, but extracting the error from the event should be in a helper function.
Again, I think we need an IDB test harness for Mocha before we can write a test for this.
There was a problem hiding this comment.
OK, sure, but the code suggestion would still improve the error message, no?
Could you create a new issue for the test harness you envision?
|
@DougReeder I activated a copilot review for you to address or ignore as you see fit! I will try to review soon |
a5fb928 to
00a7b66
Compare
sync-done should always pass a message object with a boolean
completedproperty.error should always pass an Error object as the message.
This PR complements remotestorage/remotestorage-widget#147