Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix lint warnings #331

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions e2e-test-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ async function pubSubPull(): Promise<void> {
headers: message.attributes,
testId,
});
} catch (e: any) {
} catch (e) {
logger.error(
'caught error from handler for scenario %s: %s',
scenario,
e
);
res = {
statusCode: Status.INTERNAL,
data: Buffer.from(e?.stack ?? String(e)),
data: Buffer.from((e as Error | undefined)?.stack ?? String(e)),
};
} finally {
if (res! === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ export class MetricExporter implements IMetricExporter {
)) {
try {
await this._sendTimeSeries(batchedTimeSeries);
} catch (err: any) {
} catch (e) {
const err = asError(e);
err.message = `Send TimeSeries failed: ${err.message}`;
failure = {sendFailed: true, error: err};
diag.error(err.message);
Expand Down Expand Up @@ -222,8 +223,9 @@ export class MetricExporter implements IMetricExporter {
}
);
});
} catch (err: any) {
diag.error(`MetricExporter: Failed to write data: ${err.message}`);
} catch (e) {
const err = asError(e);
diag.error('MetricExporter: Failed to write data: %s', err.message);
}
}

Expand Down Expand Up @@ -258,3 +260,10 @@ export class MetricExporter implements IMetricExporter {
return (await this._auth.getClient()) as JWT;
}
}

function asError(error: unknown): Error {
if (error instanceof Error) {
return error;
}
return new Error(String(error));
}
13 changes: 11 additions & 2 deletions packages/opentelemetry-cloud-trace-exporter/src/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export class TraceExporter implements SpanExporter {
diag.debug('Google Cloud Trace batch writing traces');
try {
this._traceServiceClient = await this._getClient();
} catch (error: any) {
} catch (e) {
const error = asError(e);
error.message = `failed to create client: ${error.message}`;
diag.error(error.message);
return {code: ExportResultCode.FAILED, error};
Expand All @@ -106,7 +107,8 @@ export class TraceExporter implements SpanExporter {
await batchWriteSpans(spans, metadata);
diag.debug('batchWriteSpans successfully');
return {code: ExportResultCode.SUCCESS};
} catch (error: any) {
} catch (e) {
const error = asError(e);
error.message = `batchWriteSpans error: ${error.message}`;
diag.error(error.message);
return {code: ExportResultCode.FAILED, error};
Expand Down Expand Up @@ -146,3 +148,10 @@ export class TraceExporter implements SpanExporter {
);
}
}

function asError(error: unknown): Error {
if (error instanceof Error) {
return error;
}
return new Error(String(error));
}