{"record":{"id":"6d847d6d5a0fe6f2","repo":"affaan-m/ECC","slug":"invalid-format-parsed-format-use-text-or-json","errorCode":null,"errorMessage":"Invalid format: ${parsed.format}. Use text or json.","messagePattern":"Invalid format: (.+?)\\. Use text or json\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/harness-audit.js","lineNumber":128,"sourceCode":"    if (arg.startsWith('--scope=')) {\n      parsed.scope = normalizeScope(arg.split('=')[1]);\n      continue;\n    }\n\n    if (arg.startsWith('--root=')) {\n      parsed.root = path.resolve(arg.slice('--root='.length));\n      continue;\n    }\n\n    if (arg.startsWith('-')) {\n      throw new Error(`Unknown argument: ${arg}`);\n    }\n\n    parsed.scope = normalizeScope(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 fileExists(rootDir, relativePath) {\n  return fs.existsSync(path.join(rootDir, relativePath));\n}\n\nfunction readText(rootDir, relativePath) {\n  return fs.readFileSync(path.join(rootDir, relativePath), 'utf8');\n}\n\nfunction countFiles(rootDir, relativeDir, extension) {\n  const dirPath = path.join(rootDir, relativeDir);\n  if (!fs.existsSync(dirPath)) {\n    return 0;\n  }","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/harness-audit.js#L110-L146","documentation":"parseArgs in scripts/harness-audit.js validates that the --format value is one of exactly two supported output formats: 'text' or 'json'. Any other value (case-sensitive) fails so downstream rendering only has to handle known formats.","triggerScenarios":"Calling `node scripts/harness-audit.js --format=markdown`, `--format=JSON` (uppercase rejected), or `--format=` (empty value after the equals sign).","commonSituations":"Case mismatch (JSON vs json), passing a format supported by another tool, scripting with a variable that is empty or unset.","solutions":["Use exactly `--format=text` or `--format=json` (lowercase)","If a variable supplies the value, echo it first to confirm it is non-empty and lowercase","Omit --format entirely to use the default","Normalize with toLowerCase() in the calling script"],"exampleFix":"// before\nnode scripts/harness-audit.js --format=JSON\n// after\nnode scripts/harness-audit.js --format=json","handlingStrategy":"validation","validationCode":"const format = (process.env.AUDIT_FORMAT || 'text').toLowerCase();\nif (!['text', 'json'].includes(format)) throw new Error(`Invalid format: ${format}`);","typeGuard":"const isAuditFormat = (v) => v === 'text' || v === 'json';","tryCatchPattern":"try {\n  parseArgs(args);\n} catch (err) {\n  if (String(err.message).startsWith('Invalid format:')) {\n    console.error(`${err.message} (accepted: text, json)`);\n    process.exit(2);\n  }\n  throw err;\n}","preventionTips":["Always lowercase --format values in wrapper scripts","Validate env-supplied values before interpolation into the command line","Default to omitting --format unless a non-default output is needed"],"tags":["cli","validation","enum"],"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"}