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

Commit 58fe3f3

Browse files
author
Matt Loring
committed
Fixes crash if gcloud project isn't identified
The debuglet currently emits events for testing purposes. When not handled outside of a testing environment, error events were causing crashes where warning and turning off the debugger is preferred. Fixes #126
1 parent 594aa68 commit 58fe3f3

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/debuglet.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Debuglet.prototype.start = function() {
8888
fs.stat(path.join(that.config_.workingDirectory, 'package.json'), function(err) {
8989
if (err && err.code === 'ENOENT') {
9090
that.logger_.error('No package.json located in working directory.');
91-
that.emit('error', new Error('No package.json found.'));
91+
that.emit('initError', new Error('No package.json found.'));
9292
return;
9393
}
9494
var id;
@@ -99,7 +99,7 @@ Debuglet.prototype.start = function() {
9999
function(err, fileStats, hash) {
100100
if (err) {
101101
that.logger_.error('Error scanning the filesystem.', err);
102-
that.emit('error', err);
102+
that.emit('initError', err);
103103
return;
104104
}
105105
that.v8debug_ = v8debugapi.create(that.logger_, that.config_, fileStats);
@@ -112,7 +112,7 @@ Debuglet.prototype.start = function() {
112112
if (err) {
113113
that.logger_.error('Unable to initialize the debuglet api' +
114114
' -- disabling debuglet', err);
115-
that.emit('error', err);
115+
that.emit('initError', err);
116116
return;
117117
}
118118

test/standalone/test-debuglet.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe(__filename, function(){
6161
.get('/computeMetadata/v1/project/numeric-project-id')
6262
.reply(404);
6363

64-
debuglet.once('error', function(err) {
64+
debuglet.once('initError', function(err) {
6565
assert(err);
6666
scope.done();
6767
done();
@@ -72,6 +72,22 @@ describe(__filename, function(){
7272
debuglet.start();
7373
});
7474

75+
it('should not crash without project num', function(done) {
76+
delete process.env.GCLOUD_PROJECT;
77+
var scope = nock('http://metadata.google.internal')
78+
.get('/computeMetadata/v1/project/numeric-project-id')
79+
.reply(404);
80+
81+
debuglet.once('started', function() {
82+
assert.fail();
83+
});
84+
setTimeout(function() {
85+
scope.done();
86+
done();
87+
}, 1500);
88+
debuglet.start();
89+
});
90+
7591
it('should accept non-numeric GCLOUD_PROJECT', function(done) {
7692
process.env.GCLOUD_PROJECT='11020304f2934';
7793

0 commit comments

Comments
 (0)