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

Commit 1db03bb

Browse files
author
Matt Loring
committed
Warn on debug logpoints
1 parent af8aa79 commit 1db03bb

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

lib/apiclasses.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ function StatusMessage(refersTo, description, isError) {
3232
this.isError = isError;
3333
}
3434

35+
// These status messages come from a proto definition.
36+
// New status messages cannot be added here.
3537
/** @const */ StatusMessage.UNSPECIFIED = 'UNSPECIFIED';
3638
/** @const */ StatusMessage.BREAKPOINT_SOURCE_LOCATION =
3739
'BREAKPOINT_SOURCE_LOCATION';

lib/debuglet.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ var assert = require('assert');
3232

3333
var NODE_VERSION_MESSAGE = 'Node.js version not supported. Node.js 5.2.0 and ' +
3434
' versions older than 0.12 are not supported.';
35+
var BREAKPOINT_ACTION_MESSAGE = 'The only currently supported breakpoint action' +
36+
' is CAPTURE.';
3537

3638
module.exports = Debuglet;
3739

@@ -215,7 +217,18 @@ Debuglet.prototype.scheduleBreakpointFetch_ = function(seconds) {
215217

216218
default:
217219
that.logger_.info('\t' + response.statusCode + ' completed.');
218-
that.updateActiveBreakpoints_(body.breakpoints || []);
220+
var bps = (body.breakpoints || []).filter(function(bp) {
221+
var action = bp.action || 'CAPTURE';
222+
if (action !== 'CAPTURE') {
223+
that.logger_.warn('Found breakpoint with invalid action:', action);
224+
bp.status = new StatusMessage(StatusMessage.UNSPECIFIED,
225+
BREAKPOINT_ACTION_MESSAGE, true);
226+
that.rejectBreakpoint_(bp);
227+
return false;
228+
}
229+
return true;
230+
});
231+
that.updateActiveBreakpoints_(bps);
219232
if (Object.keys(that.activeBreakpointMap_).length) {
220233
that.logger_.breakpoints(Logger.INFO, 'Active Breakpoints:',
221234
that.activeBreakpointMap_);
@@ -353,7 +366,20 @@ Debuglet.prototype.completeBreakpoint_ = function(breakpoint) {
353366
});
354367
};
355368

369+
/**
370+
* Update the server that the breakpoint cannot be handled.
371+
* @param {Breakpoint} breakpoint
372+
* @private
373+
*/
374+
Debuglet.prototype.rejectBreakpoint_ = function(breakpoint) {
375+
var that = this;
356376

377+
that.debugletApi_.updateBreakpoint(breakpoint, function(err/*, body*/) {
378+
if (err) {
379+
that.logger_.error('Unable to complete breakpoint on server', err);
380+
}
381+
});
382+
};
357383

358384
/**
359385
* This schedules a delayed operation that will delete the breakpoint from the

test/standalone/test-debuglet.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ nock.disableNetConnect();
3232
var debuglet;
3333
var bp = {
3434
id: 'test',
35+
action: 'CAPTURE',
36+
location: { path: 'fixtures/foo.js', line: 2 }
37+
};
38+
var logBp = {
39+
id: 'testLog',
40+
action: 'LOG',
3541
location: { path: 'fixtures/foo.js', line: 2 }
3642
};
3743

@@ -158,13 +164,20 @@ describe(__filename, function(){
158164
.reply(409)
159165
.get(BPS_PATH)
160166
.reply(200, {
161-
breakpoints: [bp]
162-
});
167+
breakpoints: [bp, logBp]
168+
})
169+
.put(BPS_PATH + '/' + logBp.id, function(body) {
170+
var status = body.breakpoint.status;
171+
return status.isError &&
172+
status.description.format.indexOf('action is CAPTURE') !== -1;
173+
})
174+
.reply(200);
163175

164176
debuglet.once('registered', function reg(id) {
165177
assert(id === DEBUGGEE_ID);
166178
setTimeout(function() {
167179
assert.deepEqual(debuglet.activeBreakpointMap_.test, bp);
180+
assert(!debuglet.activeBreakpointMap_.testLog);
168181
scope.done();
169182
done();
170183
}, 1000);
@@ -178,6 +191,7 @@ describe(__filename, function(){
178191
it('should report error on breakpoint set', function(done) {
179192
var errorBp = {
180193
id: 'test',
194+
action: 'CAPTURE',
181195
location: { path: 'fixtures/foo', line: 2 }
182196
};
183197

0 commit comments

Comments
 (0)