{"record":{"id":"c157397baf9255c6","repo":"mozilla/pdf.js","slug":"index-was-given-without-a-value","errorCode":null,"errorMessage":"--index was given without a value","messagePattern":"--index was given without a value","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gulpfile.mjs","lineNumber":886,"sourceCode":"      }\n    }\n  }\n}\n\n// Builds the coverage_search command line. By default the published index is\n// downloaded; an explicit --index=<path> selects a local index instead, used\n// read-only so it's never overwritten by the published copy.\nfunction getCoverageSearchArgs(codeArg) {\n  const searchArgs = [\n    path.join(__dirname, \"external/ccov/coverage_search.mjs\"),\n    `--code=${codeArg}`,\n  ];\n  const indexArg = getArgValue(\"--index\");\n  if (indexArg === \"\") {\n    // An explicit but empty value (e.g. an unset shell variable expanding to\n    // `--index=`) almost certainly isn't intended; fail loudly rather than\n    // silently falling back to the downloaded index.\n    throw new Error(\"--index was given without a value\");\n  }\n  if (indexArg) {\n    searchArgs.push(`--index=${indexArg}`, \"--no-download\");\n  } else if (process.argv.includes(\"--no-download\")) {\n    searchArgs.push(\"--no-download\");\n  }\n  return searchArgs;\n}\n\n// Returns the set of test IDs defined in the local ref-test manifest, or null\n// when it can't be read. Used to drop coverage-derived IDs that don't exist on\n// this branch (e.g. a test renamed since the published index was built), which\n// would otherwise make test.mjs reject the entire run.\nfunction readManifestTestIds() {\n  try {\n    const manifestFile = process.env.PDF_TEST || \"test_manifest.json\";\n    const manifest = JSON.parse(\n      fs.readFileSync(path.join(__dirname, TEST_DIR, manifestFile), \"utf8\")","sourceCodeStart":868,"sourceCodeEnd":904,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/gulpfile.mjs#L868-L904","documentation":"During coverage-driven test selection, gulpfile.mjs reads an optional `--index=<path>` argument that points to a local coverage_search index (used read-only instead of downloading the published one). `getArgValue('--index')` returns the empty string only when the flag was explicitly passed with no value (e.g. `--index=` from an unset shell variable like `$PDFJS_CCOV_INDEX`). An empty value is treated as a mistake — silently falling back to the downloaded index would hide a misconfigured pipeline, so the build fails loudly.","triggerScenarios":"Invoking the coverage test task with `--index=` (trailing equals, no path); an env var like `--index=$INDEX_FILE` where `$INDEX_FILE` is unset; quoting that strips the value (`--index=\"\"`).","commonSituations":"CI scripts that conditionally pass `--index` driven by an env var that is not set on this branch/job; copy-pasting a command template and forgetting to fill in the path.","solutions":["Provide a real path: `gulp test --code=foo --index=/path/to/ccov/index.json`, or drop `--index` entirely to use the auto-downloaded index.","If driven by an env var, default it: `--index=${INDEX_FILE:-./external/ccov/index.json}` or omit the flag when empty.","Check for stray `=` or empty quotes in your shell invocation.","Audit the CI job that sets the index variable (it may be gated on the wrong condition)."],"exampleFix":"# before\ngulp test --code=$CODE --index=$INDEX_FILE   # $INDEX_FILE unset -> '--index='\n# after\nINDEX_FILE=${INDEX_FILE:-}\ngulp test --code=$CODE ${INDEX_FILE:+--index=$INDEX_FILE}","handlingStrategy":"validation","validationCode":"// Validate the --index argv before letting gulpfile parse it.\nfunction validateIndexArg(argv) {\n  const i = argv.indexOf('--index');\n  if (i === -1) return null;\n  const next = argv[i + 1];\n  const inline = argv[i].startsWith('--index=') ? argv[i].slice(8) : next;\n  if (!inline) throw new Error('--index requires a non-empty path');\n  return inline;\n}","typeGuard":null,"tryCatchPattern":"try {\n  runGulp('test', ['--code', code, `--index=${idx}`]);\n} catch (e) {\n  if (/--index was given without a value/.test(e.message)) {\n    runGulp('test', ['--code', code]); // fall back to downloaded index\n  } else throw e;\n}","preventionTips":["Use shell parameter expansion to omit empty values: `${IDX:+--index=$IDX}`.","Document that `--index=` with no value is an error, not a default.","Default unset env vars explicitly in CI YAML before passing to gulp."],"tags":["cli","build","coverage","configuration","argv"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}