@@ -25,7 +25,14 @@ const env = process.env;
2525// TypeScript users of the error reporting library would
2626// need to install @types /console-log-level to compile their
2727// code. As a result, the interface is explicitly specified instead.
28- export type LogLevel = 'error' | 'trace' | 'debug' | 'info' | 'warn' | 'fatal' | undefined ;
28+ export type LogLevel =
29+ | 'error'
30+ | 'trace'
31+ | 'debug'
32+ | 'info'
33+ | 'warn'
34+ | 'fatal'
35+ | undefined ;
2936export interface Logger {
3037 error ( ...args : Array < { } > ) : void ;
3138 trace ( ...args : Array < { } > ) : void ;
@@ -35,14 +42,14 @@ export interface Logger {
3542 fatal ( ...args : Array < { } > ) : void ;
3643}
3744
38- export type ReportMode = 'production' | 'always' | 'never' ;
45+ export type ReportMode = 'production' | 'always' | 'never' ;
3946
4047export interface ConfigurationOptions {
4148 projectId ?: string ;
4249 keyFilename ?: string ;
43- logLevel ?: string | number ;
50+ logLevel ?: string | number ;
4451 key ?: string ;
45- serviceContext ?: { service ?: string ; version ?: string ; } ;
52+ serviceContext ?: { service ?: string ; version ?: string } ;
4653 ignoreEnvironmentCheck ?: boolean ;
4754 reportMode ?: ReportMode ;
4855 credentials ?: { } ;
@@ -78,15 +85,15 @@ export interface ServiceContext {
7885export class Configuration {
7986 _logger : Logger ;
8087 _reportMode : ReportMode ;
81- _projectId : string | null ;
82- _key : string | null ;
83- keyFilename : string | null ;
84- credentials : { } | null ;
88+ _projectId : string | null ;
89+ _key : string | null ;
90+ keyFilename : string | null ;
91+ credentials : { } | null ;
8592 _serviceContext : ServiceContext ;
8693 _reportUnhandledRejections : boolean ;
8794 _givenConfiguration : ConfigurationOptions ;
8895
89- constructor ( givenConfig : ConfigurationOptions | undefined , logger : Logger ) {
96+ constructor ( givenConfig : ConfigurationOptions | undefined , logger : Logger ) {
9097 /**
9198 * The _logger property caches the logger instance created at the top-level
9299 * for configuration logging purposes.
@@ -232,24 +239,21 @@ export class Configuration {
232239
233240 if ( is . object ( this . _givenConfiguration . serviceContext ) ) {
234241 if ( is . string ( this . _givenConfiguration . serviceContext ! . service ) ) {
235- this . _serviceContext . service =
236- this . _givenConfiguration . serviceContext ! . service ! ;
242+ this . _serviceContext . service = this . _givenConfiguration . serviceContext ! . service ! ;
237243 } else if ( has ( this . _givenConfiguration . serviceContext , 'service' ) ) {
238244 throw new Error ( 'config.serviceContext.service must be a string' ) ;
239245 }
240246
241247 if ( is . string ( this . _givenConfiguration . serviceContext ! . version ) ) {
242- this . _serviceContext . version =
243- this . _givenConfiguration . serviceContext ! . version ;
248+ this . _serviceContext . version = this . _givenConfiguration . serviceContext ! . version ;
244249 } else if ( has ( this . _givenConfiguration . serviceContext , 'version' ) ) {
245250 throw new Error ( 'config.serviceContext.version must be a string' ) ;
246251 }
247252 }
248253 }
249254 _determineReportMode ( ) {
250255 if ( this . _givenConfiguration . reportMode ) {
251- this . _reportMode =
252- this . _givenConfiguration . reportMode . toLowerCase ( ) as ReportMode ;
256+ this . _reportMode = this . _givenConfiguration . reportMode . toLowerCase ( ) as ReportMode ;
253257 }
254258 }
255259 /**
@@ -269,36 +273,43 @@ export class Configuration {
269273 let isReportModeValid = true ;
270274 if ( has ( this . _givenConfiguration , 'reportMode' ) ) {
271275 const reportMode = this . _givenConfiguration . reportMode ;
272- isReportModeValid = is . string ( reportMode ) &&
273- ( reportMode === 'production' || reportMode === 'always' ||
274- reportMode === 'never' ) ;
276+ isReportModeValid =
277+ is . string ( reportMode ) &&
278+ ( reportMode === 'production' ||
279+ reportMode === 'always' ||
280+ reportMode === 'never' ) ;
275281 }
276282
277283 if ( ! isReportModeValid ) {
278284 throw new Error (
279- 'config.reportMode must a string that is one ' +
280- 'of "production", "always", or "never".' ) ;
285+ 'config.reportMode must a string that is one ' +
286+ 'of "production", "always", or "never".'
287+ ) ;
281288 }
282289
283290 const hasEnvCheck = has ( this . _givenConfiguration , 'ignoreEnvironmentCheck' ) ;
284291 const hasReportMode = has ( this . _givenConfiguration , 'reportMode' ) ;
285292 if ( hasEnvCheck ) {
286293 this . _logger . warn (
287- 'The "ignoreEnvironmentCheck" config option is deprecated. ' +
288- 'Use the "reportMode" config option instead.' ) ;
294+ 'The "ignoreEnvironmentCheck" config option is deprecated. ' +
295+ 'Use the "reportMode" config option instead.'
296+ ) ;
289297 }
290298 if ( hasEnvCheck && hasReportMode ) {
291- this . _logger . warn ( [
292- 'Both the "ignoreEnvironmentCheck" and "reportMode" configuration options' ,
293- 'have been specified. The "reportMode" option will take precedence.'
294- ] . join ( ' ' ) ) ;
299+ this . _logger . warn (
300+ [
301+ 'Both the "ignoreEnvironmentCheck" and "reportMode" configuration options' ,
302+ 'have been specified. The "reportMode" option will take precedence.' ,
303+ ] . join ( ' ' )
304+ ) ;
295305 this . _determineReportMode ( ) ;
296306 } else if ( hasEnvCheck ) {
297307 if ( this . _givenConfiguration . ignoreEnvironmentCheck === true ) {
298308 this . _reportMode = 'always' ;
299309 } else if (
300- has ( this . _givenConfiguration , 'ignoreEnvironmentCheck' ) &&
301- ! is . boolean ( this . _givenConfiguration . ignoreEnvironmentCheck ) ) {
310+ has ( this . _givenConfiguration , 'ignoreEnvironmentCheck' ) &&
311+ ! is . boolean ( this . _givenConfiguration . ignoreEnvironmentCheck )
312+ ) {
302313 throw new Error ( 'config.ignoreEnvironmentCheck must be a boolean' ) ;
303314 } else {
304315 this . _reportMode = 'production' ;
@@ -308,12 +319,14 @@ export class Configuration {
308319 }
309320
310321 if ( this . isReportingEnabled ( ) && ! this . getShouldReportErrorsToAPI ( ) ) {
311- this . _logger . warn ( [
312- 'The stackdriver error reporting client is configured to report errors' ,
313- 'if and only if the NODE_ENV environment variable is set to "production".' ,
314- 'Errors will not be reported. To have errors always reported, regardless of the' ,
315- 'value of NODE_ENV, set the reportMode configuration option to "always".'
316- ] . join ( ' ' ) ) ;
322+ this . _logger . warn (
323+ [
324+ 'The stackdriver error reporting client is configured to report errors' ,
325+ 'if and only if the NODE_ENV environment variable is set to "production".' ,
326+ 'Errors will not be reported. To have errors always reported, regardless of the' ,
327+ 'value of NODE_ENV, set the reportMode configuration option to "always".' ,
328+ ] . join ( ' ' )
329+ ) ;
317330 }
318331
319332 if ( is . string ( this . _givenConfiguration . key ) ) {
@@ -332,8 +345,7 @@ export class Configuration {
332345 throw new Error ( 'config.credentials must be a valid credentials object' ) ;
333346 }
334347 if ( is . boolean ( this . _givenConfiguration . reportUnhandledRejections ) ) {
335- this . _reportUnhandledRejections =
336- this . _givenConfiguration . reportUnhandledRejections ! ;
348+ this . _reportUnhandledRejections = this . _givenConfiguration . reportUnhandledRejections ! ;
337349 } else if ( has ( this . _givenConfiguration , 'reportUnhandledRejections' ) ) {
338350 throw new Error ( 'config.reportUnhandledRejections must be a boolean' ) ;
339351 }
@@ -385,9 +397,11 @@ export class Configuration {
385397 * @returns {Boolean } - whether errors should be reported to the API
386398 */
387399 getShouldReportErrorsToAPI ( ) {
388- return this . _reportMode === 'always' ||
389- ( this . _reportMode === 'production' &&
390- ( process . env . NODE_ENV || '' ) . toLowerCase ( ) === 'production' ) ;
400+ return (
401+ this . _reportMode === 'always' ||
402+ ( this . _reportMode === 'production' &&
403+ ( process . env . NODE_ENV || '' ) . toLowerCase ( ) === 'production' )
404+ ) ;
391405 }
392406 isReportingEnabled ( ) {
393407 return this . _reportMode !== 'never' ;
0 commit comments