I'm using a DB query builder library that presents a chaining-style API, e.g.:
const query = db.select(...).from(...).where(...);
The query is executed when you `await` it, e.g.:
const results = await query;
Standalone example:
function gap() {
return new Promise(resolve => setTimeout(resolve, 1));
}
// A class that has it's own 'then' method.
class Query {
constructor(f) {
this.f = f;
}
then(onFulfilled, onRejected) {
this.f()
.then(r => onFulfilled ? onFulfilled(r) : r)
.catch(onRejected);
}
}
async function f1() {
try {
await f2();
}
catch (err) {
console.log('err', err);
}
}
async function f2() {
await gap();
await f3();
}
async function f3() {
await gap();
await new Query(async () => { throw new Error('query error'); });
}
In the Chrome 88.0.4324.150 (Mac):
> await f1();
err Error: query error
at Query.f (<anonymous>:31:45)
at Query.then (<anonymous>:11:18)
I get the same thing in Node 14.15.0, which is what I'm actually using.
In Firefox 85.0.2 (Mac):
await f1();
err Error: query error f3 debugger eval code:31
then debugger eval code:11
promise callback*f3 debugger eval code:31
f2 debugger eval code:27
f1 debugger eval code:19
<anonymous> debugger eval code:2
<anonymous> debugger eval code:3
Is there a way to modify the DB query builder library to work well with V8 async stack traces without modifying the library's public API?