Last active
November 26, 2017 05:58
-
-
Save jamischarles/f6abe05291c844c28a24465e7849d7ae to your computer and use it in GitHub Desktop.
node debugging via inspector api
This file contains 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
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