Comments (3)
We've been down this road before. How can we abort portably without replicating node::FatalError()?
from node-addon-api.
Previous discussion was about being able to call node::FatalError()
(or equivalent) in the implementation of some functions in node_api.cc
. But that wasn't really necessary since they could return error codes instead.
In this case, if N-API functions fail when handling an error in the C++ wrapper, then the options are:
- Silently ignore the error on release builds (assert on debug builds)
- Throw some other kind of C++ exception (not expected by the caller, and if N-API isn't working then the caller can't do anything reasonable to handle it)
- Abort in some other way such as
std::abort()
(which wouldn't provide any diagnostic information).
The suggestion here is to expose a fatal error function directly as napi_fatal_error()
, so that native addons (and the C++ wrapper) can call it. Now, we'll still have the problem that node::FatalError()
doesn't exist on older versions of Node. So, for those versions at least, we may have to replicate it. But I think that's OK, if the new API is justified.
Now, all this may be a waste of effort since napi_get_last_error_info()
and napi_create_error()
are unlikely to fail for any reason other than invalid args. That's why I originally thought just assertions would be sufficient, since any error is more likely to be just a coding mistake during development.
from node-addon-api.
This was done in #70
from node-addon-api.
Related Issues (20)
- Getting sigsegv when passing functions as parameters and building on M1 HOT 4
- Are native addons affected by Node's max memory size constraint? HOT 2
- Running single AsyncWorker at a time HOT 3
- <doc/setup.md> seems outdated HOT 1
- Query on reading/writing js typed arrays from C module. HOT 2
- Request a c++ call js demo. HOT 3
- How to properly handle `Object/Buffer/Uint8Array` in `AsyncWorker`? HOT 9
- How about add C++20 coroutine support to `Napi::Value`? HOT 9
- Node throws exception in main thread (?) when trying to execute event via ThreadSafeFunction HOT 2
- Throwing an object as an exception? HOT 3
- Napi::Value is not properly initialized the first time a program is run HOT 22
- Strange behavior HOT 2
- How do I initialize a variable of type napi_value to NULL to avoid compiler warnings HOT 4
- Failures with VS2022 HOT 4
- Added 22 to test matrixes/deprecate EOL Node.js versions. HOT 2
- Add wrappers for `node_api_nogc_env` and `node_api_nogc_finalize` HOT 8
- `function_reference` test failure when using Debug build of node v20.13.1
- Turn on experimental in ci-win.yml
- Next release HOT 1
- Differentiate an instance of Uint8Array versus Buffer HOT 6
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 node-addon-api.