Skip to content

Commit 329128a

Browse files
committed
fix(vscode): cap every summary line, not just the multi-line branch
.slice(0, 400) bound to the template literal rather than the conditional, so a single-line error came back uncapped — a registry answering with one long JSON line would print unbounded in both the retry warning and the target summary. Verified before the fix: a 500-character single-line error returned 500, while the multi-line path already capped at 400. The limit is now a named constant so the test asserts against it.
1 parent 88222ec commit 329128a

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

apps/vscode/scripts/publish-retry.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const AUTH_PATTERN = /\b401\b|unauthorized|invalidaccess|access denied|not allow
88

99
export const DEFAULT_ATTEMPTS = 3;
1010

11+
/** Longest summary line worth printing; registry errors can be one huge JSON blob. */
12+
export const SUMMARY_LIMIT = 400;
13+
1114
export function messageOf(error) {
1215
return error instanceof Error ? error.message : String(error);
1316
}
@@ -27,7 +30,9 @@ export function summaryLine(error) {
2730
.filter((line) => line !== '');
2831
if (lines.length === 0) return '';
2932
const [wrapper, ...rest] = lines;
30-
return rest.length === 0 ? wrapper : `${wrapper} ${rest.join(' ')}`.slice(0, 400);
33+
// Cap the whole result, not just the joined branch: a registry that answers
34+
// with one long JSON line would otherwise print unbounded.
35+
return (rest.length === 0 ? wrapper : `${wrapper} ${rest.join(' ')}`).slice(0, SUMMARY_LIMIT);
3136
}
3237

3338
/**

apps/vscode/test/publish-retry.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, it, vi } from 'vitest';
22

33
// @ts-expect-error -- plain .mjs build script, no type declarations
4-
import { classifyError, publishEachTarget, summaryLine, withRetry } from '../scripts/publish-retry.mjs';
4+
import { classifyError, publishEachTarget, SUMMARY_LIMIT, summaryLine, withRetry } from '../scripts/publish-retry.mjs';
55

66
const TARGETS = ['darwin-x64', 'darwin-arm64', 'linux-x64'];
77
const FILES = TARGETS.map((target) => `/tmp/${target}.vsix`);
@@ -67,6 +67,13 @@ describe('summaryLine', () => {
6767
expect(line).toContain('exited with code 1');
6868
});
6969

70+
it('caps a long error whether or not it has a second line', () => {
71+
// The cap used to bind only to the joined branch, so a registry answering
72+
// with one long JSON line printed in full.
73+
expect(summaryLine(new Error('x'.repeat(500)))).toHaveLength(SUMMARY_LIMIT);
74+
expect(summaryLine(new Error(`wrapper:\n${'y'.repeat(500)}`))).toHaveLength(SUMMARY_LIMIT);
75+
});
76+
7077
it('leaves a single-line error alone and survives a blank one', () => {
7178
expect(summaryLine(new Error('Response code 401 (Unauthorized)')))
7279
.toBe('Response code 401 (Unauthorized)');

0 commit comments

Comments
 (0)