-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catch and emit error from idb.openDB #15
base: master
Are you sure you want to change the base?
Conversation
I should also point out that one can also |
Thanks for this @jpobley! I think that Could you please do a small modification and change this to: this.whenSynced = new Promise(..)
this.whenSynced.catch(err => { this.emit('error', ..) }) Otherwise This issue is fairly preventable. The example should probably show that you only create a y-indexeddb provider when IndexedDB is supported and enabled. Not sure how one can check for that. |
548e2f6
to
42d751f
Compare
Cool. Updated. I wasn't entirely sure what you meant by your request, so lemme know if I misunderstood it.
Yeah, you'd think there would be a flag set or something, but I haven't found anything. One idea off the cuff might be updating import {uuidv4} from './random.js'
export const isEnabled = (function checkIdbEnabled() {
let idbEnabled;
const name = `lib0-idb-enabled-check-${uuidv4()}`;
const request = indexedDB.open(name)
request.onerror = e => idbEnabled = false
request.onsuccess = e => {
e.target.result.close()
indexedDB.deleteDatabase(name)
idbEnabled = true
}
return () => idbEnabled
})() |
this.synced = true | ||
return this | ||
}) | ||
this.whenSynced = promise.create((resolve, reject) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this change about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I guess I misunderstood your ask. Above, you requested this change:
this.whenSynced = new Promise(..)
this.whenSynced.catch(err => { this.emit('error', ..) })
Which I interpreted to mean that you wanted this.whenSynced
to be a new Promise instead of the Promise returned from this._db
.
What would you like me to do instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, got it. Don't take my above comment too literally. The second part this.whenSynced.catch(err => { this.emit('error', ..) })
is fine. The first part adds five extra lines of code with no apparent benefit. Please rework the PR to include a minimal amount of changes.
Firefox Private Browsing disables IndexedDb by default, which causes an error. We need to catch and emit that error so clients using
IndexedDbProvider
can do something about it.It turns out there is a workaround, but if we don't catch the error, we can't suggest it.