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)
- useLiveQuery losing items reference
- useLiveQuery
- Dexie Cloud not syncing yet in a Tauri App on Windows HOT 1
- Sync changes with purpose full for expired licenses HOT 2
- Inconsistent sync between devices HOT 1
- Waiting for data sync before running useEffect HOT 2
- token updated, but how to get it? HOT 3
- Cloud: Conditionally prevent sync HOT 2
- Run liveQuery with a custom indexedDb [request] HOT 1
- Can't put middleware higher than Dexie Cloud HOT 4
- What is expected support period for v3? (Especially for security patches) HOT 1
- Microsoft Edge Third-party cookie warning HOT 2
- Sorting and Pagination Related Issues HOT 1
- Parallelism of `toArray` within a single transaction HOT 4
- 2 samples not functional because "Typeson is not defined" HOT 3
- Cannot read properties of null (reading 'substring') HOT 3
- Cache error after bulkPut failures HOT 2
- For a custom auth integration with Dexie cloud, how does one initiate a login from a server after user info has been collected?
- db import with outdated claims throws websocket error HOT 2
- Filter AND Order / Sort? HOT 2
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.