{"record":{"id":"08b5d8f2e0edaf4d","repo":"affaan-m/ECC","slug":"invalid-format-parsed-format-use-text-or-json-08b5d8","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/observability-readiness.js","lineNumber":72,"sourceCode":"      continue;\n    }\n\n    if (arg === '--root') {\n      parsed.root = path.resolve(readValue(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 fileExists(rootDir, relativePath) {\n  return fs.existsSync(path.join(rootDir, relativePath));\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 safeParseJson(text) {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/observability-readiness.js#L54-L90","documentation":"After parsing, parseArgs validates that the --format value is one of the two supported output formats, text or json. Any other value throws this error before any report generation runs. This is a whitelist check preventing downstream rendering from encountering unknown formats.","triggerScenarios":"Running with `--format yaml`, `--format table`, or any misspelled value like `--format Json` (case-sensitive check); also --format followed by an unexpected token that slipped through readValue.","commonSituations":"Assuming more formats are supported (csv, markdown); shell casing differences like JSON vs json; an env-interpolated FORMAT variable holding an unsupported default.","solutions":["Use --format text or --format json exactly (lowercase).","Fix casing, e.g. --format JSON -> --format json.","Fix typos in the format value.","If another format is genuinely needed, extend the whitelist array in parseArgs and the corresponding renderer."],"exampleFix":"// before\nnode scripts/observability-readiness.js --format yaml\n// after\nnode scripts/observability-readiness.js --format json","handlingStrategy":"validation","validationCode":"const i = args.indexOf('--format');\nconst fmt = i !== -1 ? args[i+1] : 'text';\nif (!['text','json'].includes(fmt)) throw new Error(`--format must be 'text' or 'json', got: ${fmt}`);","typeGuard":"const isReportFormat = (v) => v === 'text' || v === 'json';","tryCatchPattern":"try {\n  runObservability(argv);\n} catch (err) {\n  if (err.message.startsWith('Invalid format:')) {\n    console.error(\"Use --format text or --format json (lowercase).\");\n  } else throw err;\n}","preventionTips":["Only pass the literal values text or json (lowercase).","Validate any env-interpolated format variable before passing it.","Don't assume additional formats (csv/yaml) are supported.","Centralize report invocation in a helper that hardcodes an allowed format."],"tags":["cli","invalid-value","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"}