Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
break on exception
Browse files Browse the repository at this point in the history
Fixes #2304
  • Loading branch information
indutny authored and ry committed Dec 19, 2011
1 parent a239ea0 commit 8085876
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions lib/_debugger.js
Expand Up @@ -236,6 +236,10 @@ Client.prototype._onResponse = function(res) {
this.emit('break', res.body);
handled = true;

} else if (res.body && res.body.event == 'exception') {
this.emit('exception', res.body);
handled = true;

} else if (res.body && res.body.event == 'afterCompile') {
this._addHandle(res.body.body.script);
handled = true;
Expand Down Expand Up @@ -409,6 +413,16 @@ Client.prototype.reqBacktrace = function(cb) {
};


// reqSetExceptionBreak(type, cb)
// TODO: from, to, bottom
Client.prototype.reqSetExceptionBreak = function(type, cb) {
this.req({
command: 'setexceptionbreak',
arguments: { type: type, enabled: true }
}, cb);
};


// Returns an array of objects like this:
//
// { handle: 11,
Expand Down Expand Up @@ -495,7 +509,7 @@ Client.prototype.mirrorObject = function(handle, depth, cb) {

var val;

if (handle.type == 'object') {
if (handle.type === 'object') {
// The handle looks something like this:
// { handle: 8,
// type: 'object',
Expand Down Expand Up @@ -695,7 +709,7 @@ function SourceUnderline(sourceText, position, tty) {


function SourceInfo(body) {
var result = 'break in ';
var result = body.exception ? 'exception in ' : 'break in ';

if (body.script) {
if (body.script.name) {
Expand All @@ -715,6 +729,8 @@ function SourceInfo(body) {
result += ':';
result += body.sourceLine + 1;

if (body.exception) result += '\n' + body.exception.text;

return result;
}

Expand Down Expand Up @@ -1599,9 +1615,11 @@ Interface.prototype.trySpawn = function(cb) {
self.setBreakpoint(bp.scriptId, bp.line, bp.condition, true);
});

if (cb) cb();

self.resume();
// Break on exceptions
client.reqSetExceptionBreak('all', function(err, res) {
cb && cb();
self.resume();
});

client.on('close', function() {
self.pause();
Expand All @@ -1622,6 +1640,10 @@ Interface.prototype.trySpawn = function(cb) {
self.handleBreak(res.body);
});

client.on('exception', function(res) {
self.handleBreak(res.body);
});

client.on('error', connectError);
function connectError() {
// If it's failed to connect 4 times then don't catch the next error
Expand Down

0 comments on commit 8085876

Please sign in to comment.