{"record":{"id":"976178d418bf5ae5","repo":"affaan-m/ECC","slug":"invalid-format-parsed-format-use-text-or-json-976178","errorCode":null,"errorMessage":"Invalid format: ${parsed.format}. Use text or json.","messagePattern":"Invalid format: (.+?)\\. Use text or json\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/preview-pack-smoke.js","lineNumber":144,"sourceCode":"      continue;\n    }\n\n    if (arg === '--root') {\n      parsed.root = path.resolve(readArgValue(args, index, arg));\n      index += 1;\n      continue;\n    }\n\n    if (arg.startsWith('--root=')) {\n      parsed.root = path.resolve(arg.slice('--root='.length));\n      continue;\n    }\n\n    throw new Error(`Unknown argument: ${arg}`);\n  }\n\n  if (!['text', 'json'].includes(parsed.format)) {\n    throw new Error(`Invalid format: ${parsed.format}. Use text or json.`);\n  }\n\n  return parsed;\n}\n\nfunction readText(rootDir, relativePath) {\n  try {\n    return fs.readFileSync(path.join(rootDir, relativePath), 'utf8');\n  } catch (_error) {\n    return '';\n  }\n}\n\nfunction fileExists(rootDir, relativePath) {\n  return fs.existsSync(path.join(rootDir, relativePath));\n}\n\nfunction safeParseJson(text) {","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/preview-pack-smoke.js#L126-L162","documentation":"parseArgs in scripts/preview-pack-smoke.js validates the parsed format value against the allowlist ['text','json'] and throws this error otherwise. The script only supports these two output formats, so any other --format value is rejected before execution proceeds.","triggerScenarios":"Passing `--format markdown`, `--format yaml`, or any value other than text or json; passing a value read from an unset env/variable yielding an empty or wrong string.","commonSituations":"Copy-pasting a --format value from platform-audit.js (which supports markdown) into this smoke script; scripting that interpolates an empty FORMAT variable; case mismatches like `--format JSON`.","solutions":["Use --format text or --format json exactly","Check for case mismatches — values are lowercase","Remove the --format flag to use the default","Don't reuse flags from other audit scripts that support more formats"],"exampleFix":"// before\nnode scripts/preview-pack-smoke.js --format markdown\n// after\nnode scripts/preview-pack-smoke.js --format json","handlingStrategy":"validation","validationCode":"function validateFormat(format) {\n  return ['text', 'json'].includes(format);\n}\nif (typeof format === 'string' && !validateFormat(format.toLowerCase())) {\n  throw new Error(`--format must be text or json, got: ${format}`);\n}","typeGuard":"function isSupportedFormat(v) {\n  return v === 'text' || v === 'json';\n}","tryCatchPattern":"try {\n  await main(process.argv);\n} catch (e) {\n  if (e.message.startsWith('Invalid format:')) {\n    console.error(`${e.message} (case-sensitive, lowercase)`);\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Only use 'text' or 'json' for this script — not markdown","Remember values are lowercase; normalize env-sourced values","Don't assume format support carries over from other audit scripts","Leave --format unset to use the default"],"tags":["cli","validation","format"],"backgroundTag":"invalid-enum-value","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}