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

Commit

Permalink
fix: Give useful message with unresolved projectID (#360)
Browse files Browse the repository at this point in the history
Fixes: #357
  • Loading branch information
DominicKramer committed Nov 14, 2017
1 parent a530d1c commit 6e0088e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/agent/debuglet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class Debuglet extends EventEmitter {
try {
project = await Debuglet.getProjectId(that.debug.options);
} catch (err) {
that.logger.error(err.message);
that.logger.error('The project ID could not be determined: ' + err.message);
that.emit('initError', err);
return;
}
Expand Down
28 changes: 28 additions & 0 deletions test/test-debuglet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,34 @@ describe('Debuglet', function() {
debuglet.start();
});

it('should give a useful error message when projectId is not available', function(done) {
const savedGetProjectId = Debuglet.getProjectId;
Debuglet.getProjectId = () => {
return Promise.reject(new Error('no project id'));
};

const debug = new Debug({}, packageInfo);
const debuglet = new Debuglet(debug, defaultConfig);

let message = '';
const savedLoggerError = debuglet.logger.error;
debuglet.logger.error = (text: string) => {
message += text;
};

debuglet.once('initError', function(err) {
Debuglet.getProjectId = savedGetProjectId;
debuglet.logger.error = savedLoggerError;
assert.ok(err);
assert(message.startsWith('The project ID could not be determined:'));
done();
});
debuglet.once('started', function() {
assert.fail('The debuglet should fail to start without a projectId');
});
debuglet.start();
});

it('should not crash without project num', function(done) {
const savedGetProjectId = Debuglet.getProjectId;
Debuglet.getProjectId = () => {
Expand Down

0 comments on commit 6e0088e

Please sign in to comment.