This repository was archived by the owner on Apr 3, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -268,7 +268,7 @@ export class Debuglet extends EventEmitter {
268268 try {
269269 project = await Debuglet . getProjectId ( that . debug . options ) ;
270270 } catch ( err ) {
271- that . logger . error ( err . message ) ;
271+ that . logger . error ( 'The project ID could not be determined: ' + err . message ) ;
272272 that . emit ( 'initError' , err ) ;
273273 return ;
274274 }
Original file line number Diff line number Diff line change @@ -397,6 +397,34 @@ describe('Debuglet', function() {
397397 debuglet . start ( ) ;
398398 } ) ;
399399
400+ it ( 'should give a useful error message when projectId is not available' , function ( done ) {
401+ const savedGetProjectId = Debuglet . getProjectId ;
402+ Debuglet . getProjectId = ( ) => {
403+ return Promise . reject ( new Error ( 'no project id' ) ) ;
404+ } ;
405+
406+ const debug = new Debug ( { } , packageInfo ) ;
407+ const debuglet = new Debuglet ( debug , defaultConfig ) ;
408+
409+ let message = '' ;
410+ const savedLoggerError = debuglet . logger . error ;
411+ debuglet . logger . error = ( text : string ) => {
412+ message += text ;
413+ } ;
414+
415+ debuglet . once ( 'initError' , function ( err ) {
416+ Debuglet . getProjectId = savedGetProjectId ;
417+ debuglet . logger . error = savedLoggerError ;
418+ assert . ok ( err ) ;
419+ assert ( message . startsWith ( 'The project ID could not be determined:' ) ) ;
420+ done ( ) ;
421+ } ) ;
422+ debuglet . once ( 'started' , function ( ) {
423+ assert . fail ( 'The debuglet should fail to start without a projectId' ) ;
424+ } ) ;
425+ debuglet . start ( ) ;
426+ } ) ;
427+
400428 it ( 'should not crash without project num' , function ( done ) {
401429 const savedGetProjectId = Debuglet . getProjectId ;
402430 Debuglet . getProjectId = ( ) => {
You can’t perform that action at this time.
0 commit comments