node-addon-api: how can i throw errors that show the trace from javascript
hello,
i want to throw via node-addon-api, but the problem is that when i catch nodejs is not receiving the trace. for example:
(async() => {
try {
const thermo = require('../../build/Release/thermo')
const pi = await thermo.piWorker(10000000)
console.log('await', pi)
} catch(e) {
console.error('node-addon-api error')
console.error(e);
}
console.log('')
try {
throw new Error('nodejs error')
} catch(e) {
console.error('nodejs error')
console.error(e)
}
})()
In C++. I am using the usual: Napi::AsyncWorker::SetError("test error");
function.
So when I use await
in the async method, it is not showing trace, so i will be hard to debug.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (7 by maintainers)
well, i use promises, the problem is, I cannot give an error, only a napi_value, which cannot be an error:
if i try to reject a promise with a Napi::Error, i get an error:
the error:
that is why i cannot pass from c++ to nodejs with promises.
sorry i do not use callbacks anymore, only promises.
the full code is: