Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Opt-in hooks and signal by default - #28

Closed
rnchamberlain wants to merge 4 commits into
nodejs:masterfrom
rnchamberlain:exception-default
Closed

rnchamberlain wants to merge 4 commits into
nodejs:masterfrom
rnchamberlain:exception-default

Conversation

@rnchamberlain

@rnchamberlain rnchamberlain commented Nov 23, 2016 •

Copy link
Copy Markdown
Contributor

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

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

@richardlau richardlau left a comment

Copy link
Copy Markdown
Member

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).

Comment thread main.js Outdated
@@ -0,0 +1,34 @@
// Main module entry point for nodereport

var api = require('./api');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const instead of var?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread main.js Outdated
var api = require('./api');

// Process NODEREPORT_EVENTS env var
var options = process.env.NODEREPORT_EVENTS;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const here as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread package.json Outdated
{
"name": "nodereport",
"main": "nodereport.node",
"main": "./main",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./ is unnecessary here.

Copy link
Copy Markdown
Contributor Author

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)

Comment thread test/test-exception.js Outdated
'Process should exit with expected signal ');
child.on('exit', (code) => {
tap.plan(3);
tap.equal(code, 1, 'Process should exit with expected return code');

Copy link
Copy Markdown
Member

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$

Copy link
Copy Markdown
Contributor Author

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.

@rnchamberlain

rnchamberlain commented Nov 24, 2016 •

Copy link
Copy Markdown
Contributor Author

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: require('nodereport').setEvents('fatalerror')which is no longer as important a use case as
1) require('nodereport') or
2) require('nodereport/api').setEvents('fatalerror')
We should probably test both of those cases, at least.

Yes docs will need updating.

@Fishrock123

Copy link
Copy Markdown
Contributor

I'll try to get to this soon. :D

Comment thread .npmignore Outdated
*
!src/**
!binding.gyp
!main.js

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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

Comment thread main.js Outdated
api.setEvents('exception+fatalerror+signal+apicall');
}

exports.triggerReport = function() {

Copy link
Copy Markdown
Contributor

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;?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, done

Comment thread main.js Outdated
};
exports.setVerbose = function() {
return api.setVerbose.apply(null, arguments);
}; No newline at end of file

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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)
@rnchamberlain

rnchamberlain commented Dec 7, 2016 •

Copy link
Copy Markdown
Contributor Author

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 node -r nodereport app.js

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 require('nodereport/api') use case in a later PR.

@Fishrock123

Copy link
Copy Markdown
Contributor

Sounds good to me. Doesn't merge tho so I didn't try it.

@rnchamberlain

Copy link
Copy Markdown
Contributor Author

As there's been some churn on my branch I'll close this and raise a new PR.

@rnchamberlain
rnchamberlain deleted the exception-default branch December 14, 2016 10:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants