This repository was archived by the owner on Jun 18, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 36
errors caught from n-api addons shouldn't trigger UncaughtException reports #133
Draft
richardlau
wants to merge
4
commits into
nodejs:main
Choose a base branch
from
richardlau:napi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bb468b5
Add test for errors thrown from n-api addon
richardlau 3cfe5f8
fixup! Add test for errors thrown from n-api addon
richardlau c58cc01
Add test for errors thrown from a nan addon
richardlau 7cf7ca4
fixup! Add test for errors thrown from n-api addon
richardlau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ | |
| # Build directories | ||
| /build/ | ||
| /node_modules/ | ||
| /test/*/build/ | ||
|
|
||
| # Package files | ||
| NodeReport*.txt | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "targets": [ | ||
| { | ||
| "target_name": "test_nan_throw", | ||
| "include_dirs": [ '<!(node -e "require(\'nan\')")' ], | ||
| "conditions": [ | ||
| ["OS=='linux'", { | ||
| "defines": [ "_GNU_SOURCE" ], | ||
| "cflags": [ "-g", "-O2", "-std=c++11", ], | ||
| }], | ||
| ], | ||
| "sources": [ | ||
| "test_nan_throw.cc" | ||
| ] | ||
| } | ||
| ] | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "name": "test_nan_throw", | ||
| "version": "1.0.0", | ||
| "description": "Throw an error.", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "install": "node-gyp rebuild" | ||
| }, | ||
| "author": "", | ||
| "license": "ISC", | ||
| "repository": "https://github.com/nodejs/node-report", | ||
| "gypfile": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #include <assert.h> | ||
|
|
||
| #include <nan.h> | ||
|
|
||
| NAN_METHOD(ThrowError) { | ||
| Nan::ThrowError("an error occurred"); | ||
| } | ||
|
|
||
| NAN_MODULE_INIT(Init) { | ||
| Nan::SetMethod(target, "throwError", ThrowError); | ||
| } | ||
|
|
||
| NODE_MODULE(NODE_GYP_MODULE_NAME, Init) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "targets": [ | ||
| { | ||
| "target_name": "test_napi_throw", | ||
| "sources": [ | ||
| "test_napi_throw.c" | ||
| ] | ||
| } | ||
| ] | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "name": "test_napi_throw", | ||
| "version": "1.0.0", | ||
| "description": "Throw an error.", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "install": "node-gyp rebuild" | ||
| }, | ||
| "author": "", | ||
| "license": "ISC", | ||
| "repository": "https://github.com/nodejs/node-report", | ||
| "gypfile": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #include <assert.h> | ||
|
|
||
| #include <node_api.h> | ||
|
|
||
| napi_value ThrowError(napi_env env, napi_callback_info info) { | ||
| napi_throw_error(env, NULL, "an error occurred"); | ||
| return NULL; | ||
| } | ||
|
|
||
| static napi_value Init(napi_env env, napi_value exports) { | ||
| napi_value result; | ||
| assert(napi_create_object(env, &result) == napi_ok); | ||
| napi_value exported_function; | ||
| assert(napi_create_function(env, | ||
| "throwError", | ||
| NAPI_AUTO_LENGTH, | ||
| ThrowError, | ||
| NULL, | ||
| &exported_function) == napi_ok); | ||
|
|
||
| assert(napi_set_named_property(env, | ||
| result, | ||
| "throwError", | ||
| exported_function) == napi_ok); | ||
| return result; | ||
| } | ||
|
|
||
| NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| 'use strict'; | ||
|
|
||
| const tap = require('tap'); | ||
|
|
||
| // Build addon that throws an error | ||
| const cp = require('child_process'); | ||
| const path = require('path'); | ||
| const build = cp.spawnSync('npm', [ 'install', '.',], | ||
| { cwd: path.join(__dirname, 'nan_throw'), | ||
| encoding: 'utf8' }); | ||
| tap.equal(build.stderr, '', 'No errors building addon'); | ||
| tap.equal(build.signal, null, 'Failed to build addon'); | ||
| tap.equal(build.status, 0, 'Failed to build addon'); | ||
|
|
||
| // Test catching the error does not trigger an UncaughtException report | ||
| const common = require('./common.js'); | ||
| const report = require('../'); | ||
| const obj = require('./nan_throw/build/Release/test_nan_throw.node'); | ||
| tap.throws(obj.throwError); | ||
|
|
||
| const reports = common.findReports(process.pid); | ||
| tap.same(reports, [], 'No reports should be generated'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| 'use strict'; | ||
|
|
||
| const tap = require('tap'); | ||
|
|
||
| // Build addon that throws an error | ||
| const cp = require('child_process'); | ||
| const path = require('path'); | ||
| const build = cp.spawnSync('npm', [ 'install', '.' ], | ||
| { cwd: path.join(__dirname, 'napi_throw'), | ||
| encoding: 'utf8' }); | ||
| tap.equal(build.stderr, '', 'No errors building addon'); | ||
| tap.equal(build.signal, null, 'Failed to build addon'); | ||
| tap.equal(build.status, 0, 'Failed to build addon'); | ||
|
|
||
| // Test catching the error does not trigger an UncaughtException report | ||
| const common = require('./common.js'); | ||
| const report = require('../'); | ||
| const obj = require('./napi_throw/build/Release/test_napi_throw.node'); | ||
| tap.throws(obj.throwError); | ||
|
|
||
| const reports = common.findReports(process.pid); | ||
| tap.same(reports, [], 'No reports should be generated'); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.