Skip to content
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
24 changes: 10 additions & 14 deletions packages/cli/src/ui/utils/updateCheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,22 +659,18 @@ describe('classifyUpdateCheckError', () => {
expect(classifyUpdateCheckError(error)).toBe('timeout');
});

it('classifies ETIMEDOUT errors as timeout', () => {
const error = new Error('request failed') as NodeJS.ErrnoException;
error.code = 'ETIMEDOUT';

expect(classifyUpdateCheckError(error)).toBe('timeout');
it.each([
'ENOTFOUND',
'ECONNREFUSED',
'EAI_AGAIN',
'ETIMEDOUT',
'ENETUNREACH',
])('classifies %s errors as offline', (code) => {
const error = new Error(`request failed`) as NodeJS.ErrnoException;
error.code = code;
expect(classifyUpdateCheckError(error)).toBe('offline');
});

it.each(['ENOTFOUND', 'ECONNREFUSED', 'EAI_AGAIN', 'ENETUNREACH'])(
'classifies %s errors as offline',
(code) => {
const error = new Error(`request failed`) as NodeJS.ErrnoException;
error.code = code;
expect(classifyUpdateCheckError(error)).toBe('offline');
},
);

it('classifies network codes embedded in the message as offline', () => {
// npm child-process failures surface the code inside stderr text only.
expect(
Expand Down
20 changes: 10 additions & 10 deletions packages/cli/src/ui/utils/updateCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const NETWORK_ERROR_CODES = [
'ENOTFOUND',
'ECONNREFUSED',
'EAI_AGAIN',
'ETIMEDOUT',
'ENETUNREACH',
];

Expand All @@ -65,7 +66,16 @@ const NETWORK_ERROR_CODES = [
export function classifyUpdateCheckError(
error: unknown,
): UpdateCheckFailureReason {
if (error instanceof UpdateCheckTimeoutError) return 'timeout';
if (error instanceof Error) {
if (
'killed' in error &&
error.killed === true &&
'signal' in error &&
error.signal === 'SIGTERM'
) {
return 'timeout';
}
const errors = [error];
Comment thread
yiliang114 marked this conversation as resolved.
if (error.cause instanceof Error) errors.push(error.cause);
const matchesCode = (code: string) =>
Expand All @@ -75,16 +85,6 @@ export function classifyUpdateCheckError(
error.message.includes(code),
);

if (
errors.some((error) => error instanceof UpdateCheckTimeoutError) ||
('killed' in error &&
error.killed === true &&
'signal' in error &&
error.signal === 'SIGTERM') ||
matchesCode('ETIMEDOUT')
) {
return 'timeout';
}
if (NETWORK_ERROR_CODES.some(matchesCode)) return 'offline';
}
return 'registry';
Expand Down
Loading