Skip to content

Commit fd5de91

Browse files
chore(deps): upgrade to gts 1.0.0 (#350)
1 parent bbaf2b8 commit fd5de91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2817
-2099
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ has instructions for running the samples.
112112

113113
| Sample | Source Code |
114114
| --------------------------- | --------------------------------- |
115-
| Examples | [source code](https://github.com/googleapis/nodejs-error-reporting/blob/master/samples/snippets.js) |
115+
| Examples | [source code](https://github.com/googleapis/nodejs-error-reporting/blob/master/samples/quickstart.js) |
116116

117117
## Configuration
118118

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"eslint-plugin-node": "^9.0.0",
8585
"eslint-plugin-prettier": "^3.0.0",
8686
"express": "^4.16.3",
87-
"gts": "^0.9.0",
87+
"gts": "^1.0.0",
8888
"hapi": "^18.0.0",
8989
"intelli-espower-loader": "^1.0.1",
9090
"js-green-licenses": "^0.5.0",

src/build-stack-trace.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,22 @@ const SRC_ROOT = __dirname;
2525
* @returns {String} - A string representation of the stack trace at the point
2626
* where this method was invoked.
2727
*/
28-
export function buildStackTrace(message?: string|null) {
28+
export function buildStackTrace(message?: string | null) {
2929
const target = {};
3030
// Build a stack trace without the frames associated with `buildStackTrace`.
3131
// The stack is located at `target.stack`.
3232
Error.captureStackTrace(target, buildStackTrace);
3333
const prefix = message ? message + '\n' : '';
3434
return (
35-
prefix +
36-
(target as {stack: string})
37-
.stack.split('\n')
38-
.slice(1)
39-
.filter((line: string) => {
40-
// Filter out all frames that are specific to the error-reporting
41-
// library
42-
return !line || line.indexOf(SRC_ROOT) === -1;
43-
})
44-
.join('\n'));
35+
prefix +
36+
(target as {stack: string}).stack
37+
.split('\n')
38+
.slice(1)
39+
.filter((line: string) => {
40+
// Filter out all frames that are specific to the error-reporting
41+
// library
42+
return !line || line.indexOf(SRC_ROOT) === -1;
43+
})
44+
.join('\n')
45+
);
4546
}

src/classes/error-message.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ import {RequestInformationContainer} from './request-information-container';
2222

2323
export interface Context {
2424
httpRequest: {
25-
method: string; url: string; userAgent: string; referrer: string;
25+
method: string;
26+
url: string;
27+
userAgent: string;
28+
referrer: string;
2629
responseStatusCode: number;
2730
remoteIp: string;
2831
};
2932
user: string;
30-
reportLocation: {filePath: string; lineNumber: number; functionName: string;};
33+
reportLocation: {filePath: string; lineNumber: number; functionName: string};
3134
}
3235

3336
export class ErrorMessage {
@@ -172,8 +175,9 @@ export class ErrorMessage {
172175
* @returns {this} - returns the instance for chaining
173176
*/
174177
setUserAgent(userAgent?: string) {
175-
this.context.httpRequest.userAgent =
176-
(is.string(userAgent) ? userAgent : '')!;
178+
this.context.httpRequest.userAgent = (is.string(userAgent)
179+
? userAgent
180+
: '')!;
177181

178182
return this;
179183
}
@@ -197,8 +201,9 @@ export class ErrorMessage {
197201
* @returns {this} - returns the instance for chaining
198202
*/
199203
setResponseStatusCode(responseStatusCode?: number) {
200-
this.context.httpRequest.responseStatusCode =
201-
(is.number(responseStatusCode) ? responseStatusCode : 0)!;
204+
this.context.httpRequest.responseStatusCode = (is.number(responseStatusCode)
205+
? responseStatusCode
206+
: 0)!;
202207

203208
return this;
204209
}
@@ -234,8 +239,9 @@ export class ErrorMessage {
234239
* @returns {this} - returns the instance for chaining
235240
*/
236241
setFilePath(filePath?: string) {
237-
this.context.reportLocation.filePath =
238-
(is.string(filePath) ? filePath : '')!;
242+
this.context.reportLocation.filePath = (is.string(filePath)
243+
? filePath
244+
: '')!;
239245

240246
return this;
241247
}
@@ -247,8 +253,9 @@ export class ErrorMessage {
247253
* @returns {this} - returns the instance for chaining
248254
*/
249255
setLineNumber(lineNumber?: number) {
250-
this.context.reportLocation.lineNumber =
251-
(is.number(lineNumber) ? lineNumber : 0)!;
256+
this.context.reportLocation.lineNumber = (is.number(lineNumber)
257+
? lineNumber
258+
: 0)!;
252259

253260
return this;
254261
}
@@ -260,8 +267,9 @@ export class ErrorMessage {
260267
* @returns {this} - returns the instance for chaining
261268
*/
262269
setFunctionName(functionName?: string) {
263-
this.context.reportLocation.functionName =
264-
(is.string(functionName) ? functionName : '')!;
270+
this.context.reportLocation.functionName = (is.string(functionName)
271+
? functionName
272+
: '')!;
265273

266274
return this;
267275
}
@@ -280,11 +288,11 @@ export class ErrorMessage {
280288
}
281289

282290
this.setHttpMethod(requestInformation.method)
283-
.setUrl(requestInformation.url)
284-
.setUserAgent(requestInformation.userAgent)
285-
.setReferrer(requestInformation.referrer)
286-
.setResponseStatusCode(requestInformation.statusCode)
287-
.setRemoteIp(requestInformation.remoteAddress);
291+
.setUrl(requestInformation.url)
292+
.setUserAgent(requestInformation.userAgent)
293+
.setReferrer(requestInformation.referrer)
294+
.setResponseStatusCode(requestInformation.statusCode)
295+
.setRemoteIp(requestInformation.remoteAddress);
288296

289297
return this;
290298
}

src/configuration.ts

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
2936
export 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

4047
export 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 {
7885
export 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

Comments
 (0)