Giter Club home page Giter Club logo

Comments (3)

gabrielschulhof avatar gabrielschulhof commented on July 27, 2024

We've been down this road before. How can we abort portably without replicating node::FatalError()?

from node-addon-api.

jasongin avatar jasongin commented on July 27, 2024

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.

jasongin avatar jasongin commented on July 27, 2024

This was done in #70

from node-addon-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.