{"record":{"id":"73c9186ec1e32354","repo":"gchq/CyberChef","slug":"unable-to-parse-javascript-br-e-message","errorCode":null,"errorMessage":"Unable to parse JavaScript.<br>${e.message}","messagePattern":"Unable to parse JavaScript\\.<br>(.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/JavaScriptBeautify.mjs","lineNumber":88,"sourceCode":"\n            const options = {\n                format: {\n                    indent: {\n                        style: beautifyIndent\n                    },\n                    quotes: quotes,\n                    semicolons: beautifySemicolons,\n                },\n                comment: beautifyComment\n            };\n\n            if (options.comment)\n                AST = escodegen.attachComments(AST, AST.comments, AST.tokens);\n\n            result = escodegen.generate(AST, options);\n        } catch (e) {\n            // Leave original error so the user can see the detail\n            throw new OperationError(\"Unable to parse JavaScript.<br>\" + e.message);\n        }\n        return result;\n    }\n\n}\n\nexport default JavaScriptBeautify;\n","sourceCodeStart":70,"sourceCodeEnd":96,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/JavaScriptBeautify.mjs#L70-L96","documentation":"Thrown by JavaScript Beautify when escodegen cannot generate code from the parsed AST. The input was parsed (espree) but code generation fails, e.g. on AST nodes escodegen does not support. Note the message injects a literal '<br>' HTML tag into the text, which renders as raw characters outside an HTML context.","triggerScenarios":"Source using newer syntax the bundled escodegen cannot emit (e.g. certain optional chaining/nullish-coalescing/private-fields forms in older builds), an AST hand-constructed incorrectly, or a parser/escodegen version mismatch. Syntax that espree parses loosely but escodegen rejects.","commonSituations":"Beautifying modern JS (ES2020+) on an older bundled toolchain. Mixing parser plugins. Files with experimental syntax flags. The '<br>' leaking into CLI/Node output as literal text.","solutions":["Simplify or modernise the toolchain: update escodegen/espree to a version supporting the syntax.","Strip the unsupported syntax before beautifying.","Replace the '<br>' with a newline so the message reads correctly in non-HTML contexts.","Use a different formatter (e.g. terser/prettier) for unsupported constructs."],"exampleFix":"// before: HTML break tag in a plain-text error message\nthrow new OperationError(\"Unable to parse JavaScript.<br>\" + e.message);\n// after: newline, readable everywhere\nthrow new OperationError(`Unable to parse JavaScript.\\n${e.message}`);","handlingStrategy":"try-catch","validationCode":"function canParseJs(src) {\n  try { espree.parse(src, { ecmaVersion: 'latest' }); return true; }\n  catch (e) { throw new Error(`JS parse failed: ${e.message}`); }\n}","typeGuard":"function isParsableJs(src) {\n  try { espree.parse(String(src), { ecmaVersion: 'latest' }); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n  return chef.JavaScriptBeautify(input);\n} catch (e) {\n  if (/Unable to parse JavaScript/.test(e.message))\n    throw new Error('Source has syntax escodegen cannot emit - simplify or upgrade the toolchain');\n  throw e;\n}","preventionTips":["Update espree/escodegen to support modern syntax.","Strip unsupported constructs before beautifying.","Replace the '<br>' with a newline so messages read in non-HTML contexts."],"tags":["javascript","beautify","escodegen","parse"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}