nodejs/node · error
command already set when parsing --test\n
Error message
command already set when parsing --test\n
What it means
The brotli CLI allows exactly one operation per invocation: compress (default), `--decompress`/`-d`, or `--test`/`-t`. The parser tracks this with `command_set`; encountering `--test` after any prior command returns COMMAND_INVALID rather than silently shadowing the earlier one.
Source
Thrown at deps/brotli/c/tools/brotli.c:577
params->junk_source = BROTLI_TRUE;
} else if (strcmp("squash", arg) == 0) {
if (squash_set) {
fprintf(stderr, "argument --squash / -s already set\n");
return COMMAND_INVALID;
}
squash_set = BROTLI_TRUE;
params->reject_uncompressible = BROTLI_TRUE;
continue;
} else if (strcmp("stdout", arg) == 0) {
if (output_set) {
fprintf(stderr, "write to standard output already set\n");
return COMMAND_INVALID;
}
output_set = BROTLI_TRUE;
params->write_to_stdout = BROTLI_TRUE;
} else if (strcmp("test", arg) == 0) {
if (command_set) {
fprintf(stderr, "command already set when parsing --test\n");
return COMMAND_INVALID;
}
command_set = BROTLI_TRUE;
command = COMMAND_TEST_INTEGRITY;
} else if (strcmp("verbose", arg) == 0) {
if (params->verbosity > 0) {
fprintf(stderr, "argument --verbose / -v already set\n");
return COMMAND_INVALID;
}
params->verbosity = 1;
} else if (strcmp("version", arg) == 0) {
/* Don't parse further. */
return COMMAND_VERSION;
} else {
/* key=value */
const char* value = strchr(arg, '=');
size_t key_len;
if (!value || value[1] == 0) {View on GitHub (pinned to 1b2de5e052)
Solutions
- Split into two invocations: one to decompress, a separate `brotli --test` for integrity checking.
- If only verifying integrity, remove the prior command flag (`--decompress`/`-z`).
- If only decompressing, remove `--test`.
Example fix
# before brotli -d --test archive.br # after (two steps) brotli -d archive.br -o archive brotli --test archive.br
Defensive patterns
Strategy: validation
Validate before calling
# Allow at most one command-mode flag.
cmds=0
for a in "$@"; do
case "$a" in
--decompress|-d|--test|-t|-z) cmds=$((cmds+1));;
esac
done
[ "$cmds" -gt 1 ] && { echo 'multiple command modes' >&2; exit 2; } Prevention
- Run integrity checks (`--test`) as a separate invocation from compression/decompression.
- Do not concatenate how-to snippets without reviewing flag conflicts.
- Remember brotli defaults to compress when no mode flag is given.
When it happens
Trigger: Invoking `brotli --decompress --test file.br`, `brotli -z --test file`, or `brotli --test --test file.br`; aliasing brotli with `-d` and then adding `--test`.
Common situations: CI jobs that combine a verification step (`--test`) with a decompression step in one command; users coming from `gzip -t` expecting to chain modes; copy-paste concatenation of two how-to snippets.
Related errors
- command already set when parsing --decompress\n
- write to standard output already set (--output)\n
- too many options passed
- quality already set
- write to standard output already set
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/7353309ebb3481da.
Report an issue: GitHub.