{"record":{"id":"2fdd94bd1c58dd13","repo":"gchq/CyberChef","slug":"unrecognized-capitalization-scope","errorCode":null,"errorMessage":"Unrecognized capitalization scope","messagePattern":"Unrecognized capitalization scope","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ToUpperCase.mjs","lineNumber":58,"sourceCode":"    run(input, args) {\n        if (!args || args.length === 0) {\n            throw new OperationError(\"No capitalization scope was provided.\");\n        }\n\n        const scope = args[0];\n\n        if (scope === \"All\") {\n            return input.toUpperCase();\n        }\n\n        const scopeRegex = {\n            \"Word\": /(\\b\\w)/gi,\n            \"Sentence\": /(?:\\.|^)\\s*(\\b\\w)/gi,\n            \"Paragraph\": /(?:\\n|^)\\s*(\\b\\w)/gi\n        }[scope];\n\n        if (scopeRegex === undefined) {\n            throw new OperationError(\"Unrecognized capitalization scope\");\n        }\n\n        // Use the regex to capitalize the input\n        return input.replace(scopeRegex, function(m) {\n            return m.toUpperCase();\n        });\n    }\n\n    /**\n     * Highlight To Upper case\n     *\n     * @param {Object[]} pos\n     * @param {number} pos[].start\n     * @param {number} pos[].end\n     * @param {Object[]} args\n     * @returns {Object[]} pos\n     */\n    highlight(pos, args) {","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ToUpperCase.mjs#L40-L76","documentation":"Thrown by CyberChef's 'To Upper case' operation when the first argument (scope) is not one of the recognised values 'All', 'Word', 'Sentence', or 'Paragraph'. The scope string indexes a regex lookup object; an unknown key yields undefined and this guard fires. In the browser UI the value comes from a fixed dropdown so this is only reachable via the Node API or a hand-built recipe.","triggerScenarios":"Invoking ToUpperCase.run(input, [scope]) with a scope value that is not exactly 'All', 'Word', 'Sentence', or 'Paragraph' (case-sensitive). For example passing ['all'], ['Words'], undefined, or an empty array after the args.length===0 guard was bypassed.","commonSituations":"Calling the operation programmatically through the CyberChef Node API with a recipe whose scope arg was copied from a different version, or passing a lowercased/localised scope label. Also seen when constructing recipes dynamically and forgetting the scope element.","solutions":["Set the scope argument to one of the exact strings: 'All', 'Word', 'Sentence', or 'Paragraph'.","If building a recipe programmatically, read the allowed values from the operation's args[0].value array rather than hardcoding.","If you want whole-string uppercasing, use scope 'All'."],"exampleFix":"// before\nchef.toUpperCase(\"hello\", [\"all\"]);\n// after\nchef.toUpperCase(\"hello\", [\"All\"]);","handlingStrategy":"validation","validationCode":"const SCOPES = [\"All\", \"Word\", \"Sentence\", \"Paragraph\"];\nif (!SCOPES.includes(scope)) {\n  throw new Error(`Invalid scope '${scope}'. Expected one of: ${SCOPES.join(\", \")}`);\n}","typeGuard":"function isValidScope(s) { return [\"All\",\"Word\",\"Sentence\",\"Paragraph\"].includes(s); }","tryCatchPattern":null,"preventionTips":["Source allowed scope values from the operation's args[0].value array instead of hardcoding.","Validate recipe args before invoking operations via the Node API."],"tags":["validation","string","argument-error","recipe"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}