Comments (4)
If you catch() the promise that is returned from then(), the error will be picked up as expected:
var db = new Dexie("testdb");
db.version(1).stores({ table1: "id" });
db.on('error', function(err) { console.log(err); });
db.open().then(function () {
console.log("before");
throw "FOO";
console.log("after");
}).catch(function (err) {
console.log("explicitely catched: " + err);
});
Output:
before
explicitely catched: FOO
However, db.on('error') should pick up all errors that the user code failed to explicitely catch and you have found a case where this fallback event doesnt work as expected. I have already put it in a unit test so that we wont forget to fix it.
from dexie.js.
Having debugged what happens I find that the reason db.on('error') didnt fire, was that the exception wasn't thrown in a database operation nor in a database transaction. That's why it doesnt bubble to db.on('error').
In fact, the code exception occurs when there is no ongoing transaction and the database has been successfully opened and code execution is handed over to the application code. So no db.on('error') should actually be fired.
One could argue that it would be handy with a static event on Promise (Promise.on('uncatched')) but that is another feature.
db.on('error') will only fire in the following scenarios:
- You are in a transaction scope and an exception occur and you dont catch the Promise returned from the db.transaction() method.
- You are doing a database operation that fails with an exception and you don't catch the resulting promise.
But not if:
- You are outside of a transaction and the error doesnt occur from within a database operation.
from dexie.js.
I've updated the documentation for Dexie.on.error to clarify it's behavior.
from dexie.js.
Thanks for the quick reply and explanation, I wasn't aware the default behaviour for promises is to swallow exceptions. Gah. I suppose we'll have to append .catch() to all promises then, until something better turns up.
from dexie.js.
Related Issues (20)
- Cloud: When the device goes offline, the errors pile up. Can the cloud stop sync & ws connection when there is no internet? HOT 2
- Guidance for multi-lingual dexie database
- Transaction.table() is missing generic overload with insert type
- Seeking Guidance for Serverless Bi-directional Sync Between Two Dexie.js Instances HOT 6
- Dexie Cloud Feature request: user-specific public realm
- Is it possible to invite a user who is not signed up? HOT 6
- Error: too much recursion HOT 1
- Typescript returns errors regarding ID that is undefined HOT 11
- bulkDelete() for large number of primary keys is way too slow
- WebPush for DexieCloud Feature Request
- Dexie Cloud feature request: in-app invitations HOT 1
- dexie cloud db entries with image blob disapear HOT 2
- Return only one field?
- Typescript complain with compound ID HOT 2
- related tables in dexie HOT 2
- Dexie Cloud Manager - "Manage users" error HOT 3
- Authentication error with the fresh.deno framework HOT 1
- Issue with Dexie's table.where() Method when Targeting Existing IndexedDB with Indexed KeyPath
- "default" is not exported by "../../../Dexie.js/dist/dexie.min.js", imported by "../../../Dexie.js/import-wrapper-prod.mjs". HOT 12
- Transaction context is lost when running a recursive call in a loop HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dexie.js.