{"record":{"id":"1cd42e2dce290f31","repo":"gchq/CyberChef","slug":"error-invalid-output-format","errorCode":null,"errorMessage":"Error: Invalid output format","messagePattern":"Error: Invalid output format","errorType":"validation","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/RegularExpression.mjs","lineNumber":171,"sourceCode":"        if (s) modifiers += \"s\";\n        if (u) modifiers += \"u\";\n        if (a) modifiers += \"A\";\n\n        if (userRegex && userRegex !== \"^\" && userRegex !== \"$\") {\n            try {\n                const regex = new XRegExp(userRegex, modifiers);\n\n                switch (outputFormat) {\n                    case \"Highlight matches\":\n                        return regexHighlight(input, regex, displayTotal);\n                    case \"List matches\":\n                        return Utils.escapeHtml(regexList(input, regex, displayTotal, true, false));\n                    case \"List capture groups\":\n                        return Utils.escapeHtml(regexList(input, regex, displayTotal, false, true));\n                    case \"List matches with capture groups\":\n                        return Utils.escapeHtml(regexList(input, regex, displayTotal, true, true));\n                    default:\n                        throw new OperationError(\"Error: Invalid output format\");\n                }\n            } catch (err) {\n                throw new OperationError(\"Invalid regex. Details: \" + err.message);\n            }\n        } else {\n            return Utils.escapeHtml(input);\n        }\n    }\n\n}\n\n/**\n * Creates a string listing the matches within a string.\n *\n * @param {string} input\n * @param {RegExp} regex\n * @param {boolean} displayTotal\n * @param {boolean} matches - Display full match","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/RegularExpression.mjs#L153-L189","documentation":"Thrown by the RegularExpression operation when the 'output format' argument does not match any of the supported cases (Highlight matches / List matches / List capture groups / List matches with capture groups). In normal UI use this is unreachable because the value comes from a dropdown, but programmatic or hand-edited recipes can hit the default branch.","triggerScenarios":"Programmatically building a recipe with a typo'd or unsupported outputFormat string; loading a recipe exported from an incompatible CyberChef version where the option name changed; an outdated config.","commonSituations":"Scripting recipes via the Node API with an invalid outputFormat; migrating recipes between CyberChef versions; locale/casing differences in the option string.","solutions":["Use one of the exact supported outputFormat strings: 'Highlight matches', 'List matches', 'List capture groups', 'List matches with capture groups'.","If scripting, validate outputFormat against an allow-list before invoking.","Re-export the recipe from a current CyberChef build to refresh option names."],"exampleFix":"// before\n//   outputFormat: \"highlight\"\n// after\n//   outputFormat: \"Highlight matches\"","handlingStrategy":"validation","validationCode":"const ALLOWED = ['Highlight matches','List matches','List capture groups','List matches with capture groups']; if (!ALLOWED.includes(outputFormat)) throw new Error('Unsupported output format');","typeGuard":"const isOutputFormat = v => ['Highlight matches','List matches','List capture groups','List matches with capture groups'].includes(v);","tryCatchPattern":"try { runRegex(input, { outputFormat }); } catch (e) { if (/Invalid output format/.test(e.message)) outputFormat='Highlight matches'; else throw e; }","preventionTips":["Validate outputFormat against the allow-list when scripting recipes.","Re-export recipes from current CyberChef versions."],"tags":["regex","validation","recipe"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}