nodejs/node · error

comment already set\n

Error message

comment already set\n

What it means

`-C B64` attaches a custom comment to the brotli stream (stored in the header). The parser latches it via `comment_set`; a second `-C` is rejected with COMMAND_INVALID because comments are singular.

Source

Thrown at deps/brotli/c/tools/brotli.c:483

          if (lgwin_set) {
            fprintf(stderr, "lgwin parameter already set\n");
            return COMMAND_INVALID;
          }
          lgwin_set = ParseInt(argv[i], 0,
                               BROTLI_MAX_WINDOW_BITS, &params->lgwin);
          if (!lgwin_set) {
            fprintf(stderr, "error parsing lgwin value [%s]\n", argv[i]);
            return COMMAND_INVALID;
          }
          if (params->lgwin != 0 && params->lgwin < BROTLI_MIN_WINDOW_BITS) {
            fprintf(stderr,
                    "lgwin parameter (%d) smaller than the minimum (%d)\n",
                    params->lgwin, BROTLI_MIN_WINDOW_BITS);
            return COMMAND_INVALID;
          }
        } else if (c == 'C') {
          if (comment_set) {
            fprintf(stderr, "comment already set\n");
            return COMMAND_INVALID;
          }
          params->comment_len = MAX_COMMENT_LEN;
          if (!ParseBase64(argv[i], params->comment, &params->comment_len)) {
            fprintf(stderr, "invalid base64-encoded comment\n");
            return COMMAND_INVALID;
          }
          comment_set = BROTLI_TRUE;
        } else if (c == 'D') {
          if (params->dictionary_path) {
            fprintf(stderr, "dictionary path already set\n");
            return COMMAND_INVALID;
          }
          params->dictionary_path = argv[i];
        } else if (c == 'S') {
          if (suffix_set) {
            fprintf(stderr, "suffix already set\n");
            return COMMAND_INVALID;

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Concatenate the comment content before encoding and pass `-C` once.
  2. Drop one of the two `-C`/`--comment` occurrences.

Example fix

# before
brotli -C AAAA -C BBBB in
# after
brotli -C "$(printf 'AAAABBBB' | base64)" in
Defensive patterns

Strategy: validation

Validate before calling

# bash: at most one comment setter
c=$(printf '%s\n' "$@" | grep -cE '^(-C|--comment.*)$')
if [ "$c" -gt 1 ]; then echo "multiple comment flags" >&2; exit 2; fi
brotli "$@"

Try / catch

# bash
if ! brotli "$@"; then rc=$?; echo "brotli exit $rc; dedupe comment flags" >&2; exit "$rc"; fi

Prevention

When it happens

Trigger: `brotli -C AAAA -C BBBB in`, or `-C` combined with `--comment=...`.

Common situations: Tooling that adds a default comment plus a user-supplied one; merging metadata-injection steps.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/0f47d509ec8a1503. Report an issue: GitHub.