Skip to content

Commit 76d798b

Browse files
committed
Tweak error logging around updates
We see quite a few 'cannot read message/statusCode' errors, with no clear cause, and EACCES errors we can do nothing about. This should explain the former and quiet the latter.
1 parent 8714987 commit 76d798b

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/error-tracking.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { randomUUID } from 'crypto';
33
import * as child_process from 'child_process';
44
import * as Sentry from '@sentry/node';
55
import { RewriteFrames } from '@sentry/integrations';
6+
import { ErrorLike } from '@httptoolkit/util';
7+
68
import { IS_PROD_BUILD } from './constants';
79

810
let sentryInitialized = false;
@@ -129,14 +131,22 @@ export function addBreadcrumb(message: string, data: Sentry.Breadcrumb) {
129131
Sentry.addBreadcrumb(Object.assign({ message }, data));
130132
}
131133

132-
export function logError(error: Error | string | unknown): undefined | Promise<void> {
134+
export function logError(error: Error | string | unknown, extra?: { cause?: ErrorLike }): undefined | Promise<void> {
133135
console.warn(error);
134136
if (!sentryInitialized) return;
135137

138+
// If we pass a cause, simplify/anonymize the cause message too if present:
139+
if (extra?.cause) {
140+
extra.cause = {
141+
...extra.cause,
142+
message: extra.cause.message ? simplifyErrorMessages(extra.cause.message) : undefined
143+
};
144+
}
145+
136146
if (typeof error === 'string') {
137-
Sentry.captureMessage(error);
147+
Sentry.captureMessage(error, { extra });
138148
} else {
139-
Sentry.captureException(error);
149+
Sentry.captureException(error, { extra });
140150
}
141151

142152
return Sentry.flush(500).then((sentSuccessfully) => {

src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ export async function runHTK(options: {
245245
return delay(1000 * 60 * 60 * 6, { unref: true });
246246
}
247247

248+
if (error.code === 'EACCES') {
249+
// We're running the server without write access to the update directory.
250+
// Weird, but it happens and there's nothing we can do - ignore it.
251+
console.log(`Update check failed: ${error.message}`);
252+
return;
253+
}
254+
248255
// Report any HTTP response errors cleanly & explicitly:
249256
if (error.statusCode) {
250257
let url: string | undefined;
@@ -263,7 +270,7 @@ export async function runHTK(options: {
263270
}
264271

265272
console.log(error.message);
266-
logError(`Failed to check for updates: ${error.message}`);
273+
logError(`Failed to check for updates: ${error.message}`, { cause: error });
267274
})
268275
);
269276
});

0 commit comments

Comments
 (0)