-
Notifications
You must be signed in to change notification settings - Fork 45
Conversation
This changes the default action on require('nodereport') to opt-in to the exception and fatal-error hooks, and to enable the signal handler. So 'node -r nodereport application.js' will get all the functionality without any code changes. For users programming to the API, a separate api-only entry point, require('nodereport/api') is provided. This does not enable the hooks and signal unless and until .setEvents() is called. Also includes a change to the behaviour on uncaught exception: default behaviour is now the same as the node default, ie no SIGILL/core dump
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits. Test fails for linux-x64 with Node.js v6.9.1.
Also documentation will need updating. Probably would be a good idea to add tests that validate reports are generated in the default cases (bonus for also checking reports are not generated for the default require('nodereport/api')
case).
@@ -0,0 +1,34 @@ | |||
// Main module entry point for nodereport | |||
|
|||
var api = require('./api'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
instead of var
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
var api = require('./api'); | ||
|
||
// Process NODEREPORT_EVENTS env var | ||
var options = process.env.NODEREPORT_EVENTS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "nodereport", | |||
"main": "nodereport.node", | |||
"main": "./main", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
./
is unnecessary here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line now removed (on Sam's suggestion to use index.js instead of main.js)
'Process should exit with expected signal '); | ||
child.on('exit', (code) => { | ||
tap.plan(3); | ||
tap.equal(code, 1, 'Process should exit with expected return code'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tried running your branch on Node.js v6.9.1 linux-x64 and got this:
-bash-4.2$ npm test
> nodereport@1.0.6 test /home/users/riclau/sandbox/github/nodereport
> tap test/test*.js
test/test-api.js ...................................... 7/7
test/test-exception.js ................................ 6/7
not ok Process should exit with expected return code
+++ found
--- wanted
-1
+0
compare: ===
at:
line: 26
column: 9
file: test/test-exception.js
type: ChildProcess
function: child.on
stack: |
ChildProcess.child.on (test/test-exception.js:26:9)
source: |
tap.equal(code, 1, 'Process should exit with expected return code');
test/test-fatal-error.js .............................. 7/7
test/test-signal.js ................................... 8/8
total ............................................... 28/29
28 passing (2s)
1 failing
npm ERR! Test failed. See above for more details.
-bash-4.2$
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reverted the change to the behaviour on uncaught exception, I think that needs a separate PR. Test now passing for me.
Ah, behavior on uncaught exception (when hooked) on v6.9.1 is different to v7.0.0. Return code is 0 instead of 1 - hence the test failure - and the exception message and stack trace on the console is missing. Investigating. Re the tests, currently we are testing for example: Yes docs will need updating. |
I'll try to get to this soon. :D |
@@ -1,3 +1,4 @@ | |||
* | |||
!src/** | |||
!binding.gyp | |||
!main.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index.js is traditional, and doesn't require config in package.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, using index.js now
api.setEvents('exception+fatalerror+signal+apicall'); | ||
} | ||
|
||
exports.triggerReport = function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not exports.triggerReport = api.triggerReport;
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, done
}; | ||
exports.setVerbose = function() { | ||
return api.setVerbose.apply(null, arguments); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ no newline at end of file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Simplify exports in index.js Revert change to default behaviour on uncaught exception Update documentation Update tests to reflect default change (setEvents() not needed)
I have reverted the change to the default behavior on uncaught exception - currently it goes to the v8 abort/sigill - will fix later in a separate PR. Docs updated to advertise For the tests, I have changed them to test the new default behavior - i.e. setEvents() calls are no longer needed. I will add tests specifically for the |
Sounds good to me. Doesn't merge tho so I didn't try it. |
As there's been some churn on my branch I'll close this and raise a new PR. |
This changes the default action on require('nodereport') to opt-in to the exception and fatal-error hooks, and to enable the signal handler. So 'node -r nodereport application.js' will get all the nodereport functionality without requiring application code changes.
For users programming to the API who don't want the invasive hooks and signal handler, a alternative api-only entry point, require('nodereport/api') is provided. This does not enable the hooks and signal unless and until .setEvents() is called.
Addresses issue #25