Skip to content

Instantly share code, notes, and snippets.

@jamischarles jamischarles/main.js
Last active Nov 26, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.