Skip to content

Instantly share code, notes, and snippets.

@jamischarles
Last active November 26, 2017 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamischarles/f6abe05291c844c28a24465e7849d7ae to your computer and use it in GitHub Desktop.
Save jamischarles/f6abe05291c844c28a24465e7849d7ae to your computer and use it in GitHub Desktop.
node debugging via inspector api
var http = require('http')
// Expectation: When I curl localhost:3000, I want to be able to
var server = http.createServer(function (req, res)
res.statusCode = 200;
res.write(e.stack); // throws exception
res.end()
})
// Goal: I'm trying to log the fn params when the exception is thrown.
// Problem:
// 1) I can't use session.connect AND inspector.open()
// 2) Even using session.post I'm unable to pause the Debugger on the uncaught exception
server.listen(3000, function () {
console.log('listening on port 3000')
const inspector = require('inspector');
// inspector.open(); // can't use this and session.connect() or Sigabort happens
var session = new inspector.Session()
session.connect();
// this logs as empty array when process crashes
session.on('Debugger.paused', ({ params }) => {
console.log('hitBreakpoints', params.hitBreakpoints);
});
// this seems to work fine
session.post('Runtime.evaluate', { expression: '2 + 2' },
(error, { result }) => console.log('result', result));
// doesn't appear to do anything
session.post('Debugger.enable', {},
(error, { result }) => {
console.log('debugger', result);
});
// doesn't appear to do anything
session.post('Debugger.setPauseOnExceptions', {state: 'all'},
(error, { result }) => console.log('debugger', result));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment