Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 4de169b

Browse files
author
Matt Loring
committed
Clean up coffeescript error messages
If compilation of a coffeescript expression fails, we will report the associated error if the coffeescript compiler provides one. Otherwise, we will just report that the compilation failed. Fixes #2
1 parent 2d45b8c commit 4de169b

File tree

2 files changed

+60
-14
lines changed

2 files changed

+60
-14
lines changed

lib/v8debugapi.js

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
V8_BREAKPOINT_ERROR: 'Unable to set breakpoint in v8',
3737
SYNTAX_ERROR_IN_CONDITION: 'Syntax error in condition: ',
3838
ERROR_EVALUATING_CONDITION: 'Error evaluating condition: ',
39+
ERROR_COMPILING_CONDITION: 'Error compiling condition.',
3940
DISALLOWED_EXPRESSION: 'Expression not allowed',
4041
SOURCE_MAP_URL_NOT_FOUND: 'The source map url could not be found in the compiled file',
4142
SOURCE_MAP_READ_ERROR: 'The source map could not be read or was incorrectly formatted',
@@ -132,7 +133,15 @@ module.exports.create = function(logger_, config_, fileStats_) {
132133
};
133134
compile = getBreakpointCompiler(breakpoint);
134135
if (breakpoint.condition && compile) {
135-
breakpoint.condition = compile(breakpoint.condition);
136+
try {
137+
breakpoint.condition = compile(breakpoint.condition);
138+
} catch (e) {
139+
logger.info('Unable to compile condition >> ' +
140+
breakpoint.condition + ' <<');
141+
return setErrorStatusAndCallback(cb, breakpoint,
142+
StatusMessage.BREAKPOINT_CONDITION,
143+
messages.ERROR_COMPILING_CONDITION);
144+
}
136145
}
137146
// TODO: more robust file finding of compiled files
138147
scriptPath = scriptPath.substr(0, scriptPath.lastIndexOf('.')) + '.js';
@@ -323,16 +332,15 @@ module.exports.create = function(logger_, config_, fileStats_) {
323332
switch(path.normalize(breakpoint.location.path).split('.').pop()) {
324333
case 'coffee':
325334
return function(uncompiled) {
326-
try {
327-
var comp = require('coffee-script');
328-
var compiled = comp.compile('0 || (' + uncompiled + ')');
329-
// Strip out coffeescript scoping wrapper to get translated condition
330-
var re = /\(function\(\) {\s*0 \|\| \((.*)\);\n\n\}\)\.call\(this\);/;
331-
var match = re.exec(compiled)[1];
332-
return match ? match.trim() : match;
333-
} catch (err) {
334-
logger.info('Unable to compile break or watch point >> ' +
335-
uncompiled + ' <<', err);
335+
var comp = require('coffee-script');
336+
var compiled = comp.compile('0 || (' + uncompiled + ')');
337+
// Strip out coffeescript scoping wrapper to get translated condition
338+
var re = /\(function\(\) {\s*0 \|\| \((.*)\);\n\n\}\)\.call\(this\);/;
339+
var match = re.exec(compiled);
340+
if (match && match.length > 1) {
341+
return match[1].trim();
342+
} else {
343+
throw new Error('Compilation Error for: ' + uncompiled);
336344
}
337345
};
338346
case 'es6':
@@ -467,16 +475,29 @@ module.exports.create = function(logger_, config_, fileStats_) {
467475
}
468476

469477
function captureBreakpointData(breakpoint, execState) {
478+
var expressionErrors = [];
470479
if (breakpoint.expressions && breakpoints[breakpoint.id].compile) {
471480
for (var i = 0; i < breakpoint.expressions.length; i++) {
472-
breakpoint.expressions[i] =
473-
breakpoints[breakpoint.id].compile(breakpoint.expressions[i]);
481+
try {
482+
breakpoint.expressions[i] =
483+
breakpoints[breakpoint.id].compile(breakpoint.expressions[i]);
484+
} catch (e) {
485+
logger.info('Unable to compile watch expression >> ' +
486+
breakpoint.expressions[i] + ' <<');
487+
expressionErrors.push({
488+
name: breakpoint.expressions[i],
489+
status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
490+
'Error Compiling Expression', true)
491+
});
492+
breakpoint.expressions.splice(i, 1);
493+
}
474494
}
475495
}
476496
var captured = state.capture(execState, breakpoint.expressions, config);
477497
breakpoint.stackFrames = captured.stackFrames;
478498
breakpoint.variableTable = captured.variableTable;
479-
breakpoint.evaluatedExpressions = captured.evaluatedExpressions;
499+
breakpoint.evaluatedExpressions =
500+
expressionErrors.concat(captured.evaluatedExpressions);
480501
}
481502

482503
/**

test/test-v8debugapi.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,21 @@ describe('v8debugapi', function() {
414414
});
415415
});
416416

417+
it('should show error for invalid conditions in coffeescript',
418+
function (done) {
419+
var bp = {
420+
id: 'coffee-id-1729',
421+
location: { path: './test/fixtures/coffee/transpile.coffee',
422+
line: 3 },
423+
condition: 'process=false'
424+
};
425+
api.set(bp, function(err) {
426+
assert(err);
427+
assert.equal(err.message, 'Error compiling condition.');
428+
done();
429+
});
430+
});
431+
417432
it('should be possible to set conditional breakpoints with babel',
418433
function (done) {
419434
var bp = {
@@ -489,6 +504,16 @@ describe('v8debugapi', function() {
489504
for (var i in bp.evaluatedExpressions) {
490505
var expr = bp.evaluatedExpressions[i];
491506
assert(expr.status && expr.status.isError);
507+
if (expr.name === ':)' ||
508+
expr.name === 'process=this' ||
509+
expr.name === 'return') {
510+
assert.equal(expr.status.description.format,
511+
'Error Compiling Expression');
512+
} else {
513+
assert.notEqual(
514+
expr.status.description.format.indexOf('Unexpected token'),
515+
-1);
516+
}
492517
}
493518

494519
api.clear(bp);

0 commit comments

Comments
 (0)