{"record":{"id":"51d40aef74ea0301","repo":"GoogleChrome/lighthouse","slug":"invalid-output-mode-outputmode","errorCode":null,"errorMessage":"Invalid output mode: ${outputMode}","messagePattern":"Invalid output mode: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"report/generator/report-generator.js","lineNumber":187,"sourceCode":"      if (outputMode === 'html') {\n        if (ReportGenerator.isFlowResult(result)) {\n          return ReportGenerator.generateFlowReportHtml(result);\n        }\n        return ReportGenerator.generateReportHtml(result);\n      }\n      // CSV report.\n      if (outputMode === 'csv') {\n        if (ReportGenerator.isFlowResult(result)) {\n          throw new Error('CSV output is not support for user flows');\n        }\n        return ReportGenerator.generateReportCSV(result);\n      }\n      // JSON report.\n      if (outputMode === 'json') {\n        return JSON.stringify(result, null, 2);\n      }\n\n      throw new Error('Invalid output mode: ' + outputMode);\n    });\n\n    return outputAsArray ? output : output[0];\n  }\n}\n\nexport {ReportGenerator};\n","sourceCodeStart":169,"sourceCodeEnd":195,"githubUrl":"https://github.com/GoogleChrome/lighthouse/blob/9515cd4e58ebed69f78742d932b501c2cab8ad8f/report/generator/report-generator.js#L169-L195","documentation":"Thrown by ReportGenerator.generateReport when an output mode string is not one of the three supported values: 'html', 'csv', or 'json'. The mode is matched by strict equality, so it is case-sensitive and typo-sensitive. The offending value is concatenated into the message for diagnostics.","triggerScenarios":"Calling ReportGenerator.generateReport(result, outputMode) with outputMode equal to e.g. 'xml', 'HTML', 'md', or an empty/undefined value. Also triggered when passing a non-string scalar that is then compared.","commonSituations":"Typos or casing mistakes ('HTML' instead of 'html'); passing a value read from an unvalidated CLI flag, env var, or config file; defaulting a missing mode to undefined. Using a newer/imagined format name not implemented by this generator.","solutions":["Use exactly one of the lowercase literals: 'html', 'csv', or 'json'.","Validate/whitelist the mode against ['html','csv','json'] before calling generateReport and fall back to a default like 'html'.","Normalize input with mode.toLowerCase().trim() if the value originates from user input."],"exampleFix":"// before\nReportGenerator.generateReport(result, mode); // mode could be 'HTML'\n\n// after\nconst VALID = ['html', 'csv', 'json'];\nconst mode = VALID.includes(String(rawMode).toLowerCase()) ? rawMode.toLowerCase() : 'html';\nReportGenerator.generateReport(result, mode);","handlingStrategy":"validation","validationCode":"const VALID_MODES = ['html', 'csv', 'json'];\nfunction normalizeMode(raw) {\n  const m = String(raw).toLowerCase().trim();\n  return VALID_MODES.includes(m) ? m : 'html';\n}\nReportGenerator.generateReport(result, normalizeMode(userMode));","typeGuard":"/** @param {unknown} m */\nfunction isValidMode(m) {\n  return typeof m === 'string' && ['html', 'csv', 'json'].includes(m);\n}","tryCatchPattern":"try {\n  ReportGenerator.generateReport(result, mode);\n} catch (err) {\n  if (err.message.startsWith('Invalid output mode:')) {\n    ReportGenerator.generateReport(result, 'html'); // safe default\n  } else throw err;\n}","preventionTips":["Whitelist output modes against ['html','csv','json'] before calling generateReport.","Normalize user/config-supplied modes with toLowerCase().trim().","Default to 'html' when the supplied mode is unrecognized rather than letting it reach the throw."],"tags":["report-generator","output-mode","validation"],"backgroundTag":null,"analyzedSha":"9515cd4e58ebed69f78742d932b501c2cab8ad8f","analyzedAt":"2026-08-13T06:28:10.346Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}