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

Commit 42277e6

Browse files
author
Matt Loring
committed
Unify warnings for using v5.2 and <v0.12
Additionally add test coverage to ensure message is printed for invalid versions.
1 parent 54c8a97 commit 42277e6

File tree

5 files changed

+87
-20
lines changed

5 files changed

+87
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
coverage
33
npm-debug.log
4+
.DS_Store

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This module provides Cloud Debug support for Node.js applications. [Google Cloud
1313
[![Cloud Debugger Intro](http://img.youtube.com/vi/tyHcK_kAOpw/0.jpg)](https://www.youtube.com/watch?v=tyHcK_kAOpw)
1414

1515
## Prerequisites
16-
* Your application will need to be using Node.js version 0.12 or greater. Node.js v5+ is recommended.
16+
* Your application will need to be using Node.js version 0.12 or greater. Node.js v5+ is recommended. (Node.js v5.2.0 is not supported on account of [this bug](https://github.com/nodejs/node/issues/4297))
1717
* The source of your application is uploaded to a [cloud source repository](https://cloud.google.com/tools/cloud-repositories/docs/). The Debugger UI needs the source to be available in order to set breakpoints.
1818

1919
## Quick Start (Node.js v4.x+)

index.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
var config = require('./config.js');
2323
var logger = require('@google/cloud-diagnostics-common').logger;
2424
var Debuglet = require('./lib/debuglet.js');
25-
var semver = require('semver');
2625

2726
// exports is populated by the agent
2827
module.exports = {};
@@ -39,11 +38,6 @@ if (process.env.hasOwnProperty('GCLOUD_DEBUG_REPO_APP_PATH')) {
3938

4039
var log = logger.create(config.logLevel, '@google/cloud-debug');
4140

42-
if (semver.satisfies(process.version, '5.2')) {
43-
log.error('Debug is not supported on Node v5.2');
44-
return;
45-
}
46-
4741
if (config.enabled) {
4842
var debuglet = new Debuglet(config, log);
4943
debuglet.start();

lib/debuglet.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818

1919
var fs = require('fs');
2020
var path = require('path');
21-
var EventEmitter = require('events');
21+
var EventEmitter = require('events').EventEmitter;
2222
var util = require('util');
23+
var semver = require('semver');
2324

2425
var v8debugapi = require('./v8debugapi.js');
2526
var DebugletApi = require('./debugletapi.js');
@@ -30,9 +31,8 @@ var StatusMessage = require('./apiclasses.js').StatusMessage;
3031

3132
var assert = require('assert');
3233

33-
var NODE_VERSION_MESSAGE = 'V8 Debug API not available – make sure you are ' +
34-
'running Node.js >=0.12. Cloud Debugger agent will not be able to take ' +
35-
'snapshots.';
34+
var NODE_VERSION_MESSAGE = 'Node.js version not supported. Node.js 5.2.0 and ' +
35+
' versions older than 0.12 are not supported.';
3636

3737
module.exports = Debuglet;
3838

@@ -110,11 +110,11 @@ Debuglet.prototype.start = function() {
110110
return;
111111
}
112112

113-
if (!that.v8debug_) {
114-
// V8 Debug API is missing. We report an error message about the Node.js
115-
// version, but we keep on running. The idea is that the user may miss
116-
// the error message on the console. This way we can report the error
117-
// when the user tries to set a breakpoint.
113+
if (semver.satisfies(process.version, '5.2 || <0.12')) {
114+
// Using an unsupported version. We report an error message about the
115+
// Node.js version, but we keep on running. The idea is that the user
116+
// may miss the error message on the console. This way we can report the
117+
// error when the user tries to set a breakpoint.
118118
that.logger_.error(NODE_VERSION_MESSAGE);
119119
}
120120

@@ -299,18 +299,16 @@ Debuglet.prototype.removeBreakpoint_ = function(breakpoint) {
299299
*/
300300
Debuglet.prototype.addBreakpoint_ = function(breakpoint, cb) {
301301
var that = this;
302-
var message;
303302

304-
if (!that.v8debug_) {
305-
message = NODE_VERSION_MESSAGE;
303+
if (semver.satisfies(process.version, '5.2 || <0.12')) {
304+
var message = NODE_VERSION_MESSAGE;
306305
that.logger_.error(message);
307306
breakpoint.status = new StatusMessage(StatusMessage.UNSPECIFIED,
308307
message, true);
309308
setImmediate(function() { cb(message); });
310309
return;
311310
}
312311

313-
314312
that.v8debug_.set(breakpoint, function(err) {
315313
if (err) {
316314
cb(err);

test/e2e/test-error-message.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
'use strict';
17+
18+
var assert = require('assert');
19+
var request = require('request');
20+
var logger = require('@google/cloud-diagnostics-common').logger;
21+
var config = require('../../config.js');
22+
var Debuglet = require('../../lib/debuglet.js');
23+
var semver = require('semver');
24+
25+
var nock = require('nock');
26+
nock.disableNetConnect();
27+
28+
describe(__filename, function() {
29+
it('should re-fetch breakpoints on error', function(done) {
30+
assert(semver.satisfies(process.version, '5.2.x'));
31+
var debuglet = new Debuglet(
32+
config, logger.create(config.logLevel, '@google/cloud-debug'));
33+
34+
process.env.GCLOUD_PROJECT_NUM=0;
35+
36+
var API = 'https://clouddebugger.googleapis.com';
37+
38+
var scope = nock(API)
39+
.post('/v2/controller/debuggees/register')
40+
.reply(200, {
41+
debuggee: {
42+
id: 'bar'
43+
}
44+
})
45+
.get('/v2/controller/debuggees/bar/breakpoints')
46+
.reply(200, {
47+
breakpoints: [{
48+
id: 'test',
49+
location: { path: 'fixtures/foo.js', line: 2 }
50+
}]
51+
})
52+
.put('/v2/controller/debuggees/bar/breakpoints/test', function(body) {
53+
var status = body.breakpoint.status;
54+
var partialMessage = 'Node.js version not supported.';
55+
return status.isError &&
56+
(status.description.format.indexOf(partialMessage) !== -1);
57+
})
58+
.reply(200);
59+
60+
debuglet.once('started', function() {
61+
debuglet.debugletApi_.request_ = request; // Avoid authing.
62+
});
63+
debuglet.once('registered', function reg(id) {
64+
assert(id === 'bar');
65+
setTimeout(function() {
66+
debuglet.stop();
67+
scope.done();
68+
done();
69+
}, 200);
70+
});
71+
72+
debuglet.start();
73+
});
74+
});

0 commit comments

Comments
 (0)