Skip to content

Commit db5c702

Browse files
ref(cli): Drop the sourcemap upload wait limit flag
`sentry sourcemap upload` never had `--wait-for` before this branch, and an optional value on `--wait` made `--wait ./dist` read the directory as the limit. `--wait` is a plain boolean again, `--no-wait` is its negation, and the five-minute limit is fixed.
1 parent a76dc25 commit db5c702

5 files changed

Lines changed: 52 additions & 145 deletions

File tree

‎apps/cli-docs/src/content/docs/migrating-from-v3.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ Two behavioral differences to be aware of:
578578
`CI` or `GITHUB_ACTIONS` is set, `sourcemap upload` waits up to five minutes
579579
for Sentry to process the upload and exits with an error if processing
580580
fails or times out. Pass `--no-wait` to return as soon as Sentry accepts the
581-
upload. `--wait` takes an optional limit in seconds, so v3's
582-
`--wait-for 60` becomes `--wait 60`; `--wait 0` waits with no limit.
581+
upload, or `--wait` to wait outside CI. The five-minute limit is fixed, so
582+
drop v3's `--wait-for`.
583583
- **`--debug-id-reference` is now automatic:** in v3 that flag let `sourcemaps
584584
upload` take the debug ID from the linked sourcemap when it couldn't verify
585585
one in the bundle itself, for example in binary bundles.

‎apps/cli-docs/src/fragments/commands/sourcemap.md‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,4 @@ Sentry processes an upload after it accepts it, and processing can still
4343
fail. In CI, `sentry sourcemap upload` waits up to five minutes for
4444
processing to finish and exits with an error if it fails or times out.
4545
Outside CI it exits once Sentry accepts the upload. Pass `--wait` or
46-
`--no-wait` to choose. `--wait <seconds>` sets a different limit, and
47-
`--wait 0` waits with no limit. Because `--wait` can take a value, put the
48-
directory before it (`sentry sourcemap upload ./dist --wait`).
46+
`--no-wait` to choose.

‎packages/cli/plugins/sentry-cli/skills/sentry-cli/references/sourcemap.md‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ Upload sourcemaps to Sentry
6565
- `--strip-common-prefix - Automatically strip the longest common path prefix from all files`
6666
- `--no-rewrite - Upload files as-is without injecting debug IDs`
6767
- `--allow-empty - Exit successfully when no JS + sourcemap pairs are found (default: error out to catch silent build misconfigurations)`
68-
- `--wait <value> - Wait for the server to fully process the uploaded files, at most this many seconds (default: on in CI, 300; 0: no limit)`
69-
- `--no-wait - Exit once Sentry accepts the upload, even in CI`
68+
- `--wait - Wait up to five minutes for the server to fully process the uploaded files (default: on in CI)`
7069

7170
**Examples:**
7271

@@ -97,9 +96,6 @@ sentry sourcemap upload ./dist --ext .js,.mjs
9796

9897
# Wait for Sentry to process the upload outside CI
9998
sentry sourcemap upload ./dist --wait
100-
101-
# Wait at most two minutes for processing
102-
sentry sourcemap upload ./dist --wait 120
10399
```
104100

105101
### `sentry sourcemap resolve <directory>`

‎packages/cli/src/commands/sourcemap/upload.ts‎

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
import type { SentryContext } from "../../context.js";
1515
import {
1616
type ArtifactFile,
17-
DEFAULT_UPLOAD_MAX_WAIT_MS,
1817
uploadSourcemaps,
1918
} from "../../lib/api/sourcemaps.js";
2019
import { isCi } from "../../lib/ci.js";
@@ -25,7 +24,6 @@ import {
2524
parseFilePath,
2625
parseRelease,
2726
parseText,
28-
textParser,
2927
} from "../../lib/completion-target.js";
3028
import { ContextError, ValidationError } from "../../lib/errors.js";
3129
import { mdKvTable, renderMarkdown } from "../../lib/formatters/markdown.js";
@@ -215,26 +213,6 @@ function buildArtifactPair(
215213
];
216214
}
217215

218-
/**
219-
* Parse the `--wait` limit into milliseconds. A bare `--wait` keeps the
220-
* default limit, and `--wait 0` waits with no limit.
221-
*/
222-
function parseWaitLimit(input: string): number {
223-
if (input === "") {
224-
return DEFAULT_UPLOAD_MAX_WAIT_MS;
225-
}
226-
const seconds = Number(input);
227-
if (!Number.isFinite(seconds) || seconds < 0) {
228-
// `--wait ./dist` reads the directory as the limit.
229-
throw new ValidationError(
230-
`--wait takes a number of seconds, not '${input}'. ` +
231-
"Put the directory before --wait, or write --wait=<seconds>.",
232-
"wait",
233-
);
234-
}
235-
return seconds === 0 ? Number.POSITIVE_INFINITY : seconds * 1000;
236-
}
237-
238216
export const uploadCommand = buildCommand({
239217
docs: {
240218
brief: "Upload sourcemaps to Sentry",
@@ -250,8 +228,7 @@ export const uploadCommand = buildCommand({
250228
"In CI, the command waits up to five minutes for Sentry to finish " +
251229
"processing the upload and exits with an error if processing fails. " +
252230
"Elsewhere it exits once Sentry accepts the upload. Pass --wait or " +
253-
"--no-wait to override. --wait takes an optional limit in seconds; " +
254-
"--wait 0 waits with no limit.",
231+
"--no-wait to override.",
255232
examples: [
256233
{
257234
description: "Upload sourcemaps from dist/",
@@ -289,10 +266,6 @@ export const uploadCommand = buildCommand({
289266
description: "Wait for Sentry to process the upload outside CI",
290267
run: "sourcemap upload ./dist --wait",
291268
},
292-
{
293-
description: "Wait at most two minutes for processing",
294-
run: "sourcemap upload ./dist --wait 120",
295-
},
296269
],
297270
},
298271
output: {
@@ -377,20 +350,12 @@ export const uploadCommand = buildCommand({
377350
default: false,
378351
},
379352
wait: {
380-
kind: "parsed",
381-
parse: textParser(parseWaitLimit),
353+
kind: "boolean",
382354
brief:
383-
"Wait for the server to fully process the uploaded files, at " +
384-
"most this many seconds (default: on in CI, 300; 0: no limit)",
355+
"Wait up to five minutes for the server to fully process the " +
356+
"uploaded files (default: on in CI)",
385357
optional: true,
386-
inferEmpty: true,
387-
placeholder: "seconds",
388-
},
389-
"no-wait": {
390-
kind: "boolean",
391-
brief: "Exit once Sentry accepts the upload, even in CI",
392-
optional: true,
393-
default: false,
358+
withNegated: true,
394359
},
395360
},
396361
},
@@ -407,21 +372,12 @@ export const uploadCommand = buildCommand({
407372
"strip-common-prefix"?: boolean;
408373
"no-rewrite"?: boolean;
409374
"allow-empty"?: boolean;
410-
wait?: number;
411-
"no-wait"?: boolean;
375+
wait?: boolean;
412376
},
413377
dir: string,
414378
) {
415-
if (flags.wait !== undefined && flags["no-wait"]) {
416-
throw new ValidationError(
417-
"--wait cannot be combined with --no-wait",
418-
"wait",
419-
);
420-
}
421379
// CI must fail when Sentry rejects the bundle, so wait there by default.
422-
const wait =
423-
flags.wait !== undefined || (!flags["no-wait"] && isCi(this.env));
424-
const maxWaitMs = flags.wait ?? DEFAULT_UPLOAD_MAX_WAIT_MS;
380+
const wait = flags.wait ?? isCi(this.env);
425381

426382
// Validate the directory and discover pairs read-only first so we
427383
// don't write debug IDs when the upload won't proceed (empty dir,
@@ -541,7 +497,6 @@ export const uploadCommand = buildCommand({
541497
dist: flags.dist,
542498
files: artifactFiles,
543499
wait,
544-
maxWaitMs,
545500
});
546501

547502
// Count actually-uploaded pairs (one minified_source entry per pair).

‎packages/cli/test/commands/sourcemap/upload.test.ts‎

Lines changed: 41 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ type UploadFuncArgs = {
3939
"strip-common-prefix"?: boolean;
4040
"no-rewrite"?: boolean;
4141
"allow-empty"?: boolean;
42-
/** Parsed `--wait` limit in milliseconds. */
43-
wait?: number;
44-
"no-wait"?: boolean;
42+
wait?: boolean;
4543
};
4644
type CmdFunc<A> = (this: unknown, flags: A, dir: string) => Promise<unknown>;
4745

@@ -401,40 +399,34 @@ describe("sourcemap upload command — --allow-empty behavior", () => {
401399
}
402400
});
403401

404-
test.each<[string, NodeJS.ProcessEnv, UploadFuncArgs, boolean, number]>([
405-
["outside CI", {}, {}, false, 300_000],
406-
["in CI", { CI: "true" }, {}, true, 300_000],
402+
test.each<[string, NodeJS.ProcessEnv, UploadFuncArgs, boolean]>([
403+
["outside CI", {}, {}, false],
404+
["in CI", { CI: "true" }, {}, true],
407405
[
408406
"in CI with --no-wait",
409407
{ GITHUB_ACTIONS: "true" },
410-
{ "no-wait": true },
408+
{ wait: false },
411409
false,
412-
300_000,
413410
],
414-
["outside CI with --wait", {}, { wait: 300_000 }, true, 300_000],
415-
["outside CI with --wait 30", {}, { wait: 30_000 }, true, 30_000],
416-
])(
417-
"waits for processing %s",
418-
async (_name, env, flags, expectedWait, expectedMaxWaitMs) => {
419-
await writeFile(join(dir, "app.js"), "console.log(1)\n");
420-
await writeFile(
421-
join(dir, "app.js.map"),
422-
JSON.stringify({ version: 3, sources: [], names: [], mappings: "" }),
423-
);
424-
const uploadSpy = vi
425-
.spyOn(sourcemapsApi, "uploadSourcemaps")
426-
.mockResolvedValue(undefined);
427-
try {
428-
await func.call(makeContext(env), flags, dir);
429-
expect(uploadSpy.mock.calls[0]?.[0]).toMatchObject({
430-
wait: expectedWait,
431-
maxWaitMs: expectedMaxWaitMs,
432-
});
433-
} finally {
434-
uploadSpy.mockRestore();
435-
}
436-
},
437-
);
411+
["outside CI with --wait", {}, { wait: true }, true],
412+
])("waits for processing %s", async (_name, env, flags, expectedWait) => {
413+
await writeFile(join(dir, "app.js"), "console.log(1)\n");
414+
await writeFile(
415+
join(dir, "app.js.map"),
416+
JSON.stringify({ version: 3, sources: [], names: [], mappings: "" }),
417+
);
418+
const uploadSpy = vi
419+
.spyOn(sourcemapsApi, "uploadSourcemaps")
420+
.mockResolvedValue(undefined);
421+
try {
422+
await func.call(makeContext(env), flags, dir);
423+
expect(uploadSpy.mock.calls[0]?.[0]).toMatchObject({
424+
wait: expectedWait,
425+
});
426+
} finally {
427+
uploadSpy.mockRestore();
428+
}
429+
});
438430

439431
test("inline sourcemap: uploads decoded map as a source_map with content", async () => {
440432
const jsPath = join(dir, "inline.js");
@@ -1158,75 +1150,41 @@ describe("sourcemap upload command — waiting for processing", () => {
11581150
expect(assembleCalls()).toBe(1);
11591151
});
11601152

1161-
test("rejects --wait with --no-wait", async () => {
1162-
const assembleCalls = serveAssembleStates([{ state: "ok" }]);
1163-
1164-
await expect(
1165-
func.call(makeContext(), { wait: 30_000, "no-wait": true }, dir),
1166-
).rejects.toThrow("--wait cannot be combined with --no-wait");
1167-
expect(assembleCalls()).toBe(0);
1168-
});
1169-
1170-
describe("--wait argument", () => {
1153+
describe("flag parsing", () => {
11711154
const app = buildApplication(
11721155
buildRouteMap({
11731156
routes: { upload: uploadCommand },
11741157
docs: { brief: "Test app" },
11751158
}),
1176-
{ name: "test" },
1159+
// The CLI's scanner style, which `--no-wait` needs.
1160+
{ name: "test", scanner: { caseStyle: "allow-kebab-for-camel" } },
11771161
);
11781162

1179-
/** Run `upload <argv>` and return the options passed to the uploader. */
1180-
async function uploadWith(argv: string[], env: NodeJS.ProcessEnv = {}) {
1181-
const stderr: string[] = [];
1163+
test.each<[string[], NodeJS.ProcessEnv, boolean]>([
1164+
[["--wait"], {}, true],
1165+
[["--no-wait"], { CI: "true" }, false],
1166+
[["--wait"], { CI: "true" }, true],
1167+
])("%o with env %o waits: %s", async (flags, env, expectedWait) => {
11821168
const uploadSpy = vi
11831169
.spyOn(sourcemapsApi, "uploadSourcemaps")
11841170
.mockResolvedValue(undefined);
11851171
try {
1186-
const write = (s: string) => {
1187-
stderr.push(s);
1188-
return true;
1189-
};
1172+
const writer = { write: () => true };
11901173
const ctx = {
1191-
process: { stdout: { write: () => true }, stderr: { write } },
1192-
stdout: { write: () => true },
1193-
stderr: { write },
1174+
process: { stdout: writer, stderr: writer },
1175+
stdout: writer,
1176+
stderr: writer,
11941177
cwd: dir,
11951178
env,
11961179
};
1197-
await run(app, ["upload", ...argv], ctx as never);
1198-
return {
1199-
options: uploadSpy.mock.calls[0]?.[0],
1200-
stderr: stderr.join(""),
1201-
};
1180+
// `--wait` before the directory must not consume it as a value.
1181+
await run(app, ["upload", ...flags, dir], ctx as never);
1182+
expect(uploadSpy.mock.calls[0]?.[0]).toMatchObject({
1183+
wait: expectedWait,
1184+
});
12021185
} finally {
12031186
uploadSpy.mockRestore();
12041187
}
1205-
}
1206-
1207-
test.each<[string[], number]>([
1208-
[["--wait"], 300_000],
1209-
[["--wait", "30"], 30_000],
1210-
[["--wait=0"], Number.POSITIVE_INFINITY],
1211-
])("%o waits with limit %d ms", async (flags, maxWaitMs) => {
1212-
const { options } = await uploadWith([dir, ...flags]);
1213-
expect(options).toMatchObject({ wait: true, maxWaitMs });
1214-
});
1215-
1216-
test("bare --wait before another flag keeps the default limit", async () => {
1217-
const { options } = await uploadWith([dir, "--wait", "--allow-empty"]);
1218-
expect(options).toMatchObject({ wait: true, maxWaitMs: 300_000 });
1219-
});
1220-
1221-
test("--no-wait skips waiting in CI", async () => {
1222-
const { options } = await uploadWith([dir, "--no-wait"], { CI: "true" });
1223-
expect(options).toMatchObject({ wait: false });
1224-
});
1225-
1226-
test("--wait followed by the directory explains the mix-up", async () => {
1227-
const { options, stderr } = await uploadWith(["--wait", dir]);
1228-
expect(options).toBeUndefined();
1229-
expect(stderr).toContain("--wait takes a number of seconds");
12301188
});
12311189
});
12321190
});

0 commit comments

Comments
 (0)