{"record":{"id":"a6c5d196d33be182","repo":"gchq/CyberChef","slug":"value-a-must-be-defined-a6c5d1","errorCode":null,"errorMessage":"Value (a) must be defined","messagePattern":"Value \\(a\\) must be defined","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ModularInverse.mjs","lineNumber":72,"sourceCode":"    run(input, args) {\n        const [aStr, mStr] = args;\n\n        // Trim everything so \"\" and \"   \" count as empty\n        const aParam = aStr?.trim();\n        const mParam = mStr?.trim();\n        const inputVal = input?.trim();\n\n        let a, m;\n\n        if (aParam && mParam) {\n            // Case 1: value and modulus both given as parameters\n            a = aParam;\n            m = mParam;\n        } else if (!aParam && mParam) {\n            // Case 2: value missing - take from input\n            a = inputVal;\n            m = mParam;\n            if (!a) throw new OperationError(\"Value (a) must be defined\");\n        } else if (aParam && !mParam) {\n            // Case 3: modulus missing - take from input\n            a = aParam;\n            m = inputVal;\n            if (!m) throw new OperationError(\"Modulus (m) must be defined\");\n        } else if (!aParam && !mParam) {\n            // Case 4: value and modulus both missing\n            throw new OperationError(\"Value (a) and Modulus (m) must be defined\");\n        }\n\n        const aBI = parseBigInt(a, \"Value (a)\");\n        const mBI = parseBigInt(m, \"Modulus (m)\");\n\n        if (mBI <= 0n) {\n            throw new OperationError(\"Modulus must be greater than zero\");\n        }\n\n        const aNorm = ((aBI % mBI) + mBI) % mBI;","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ModularInverse.mjs#L54-L90","documentation":"Thrown by Modular Inverse in Case 2: the Value (a) argument is blank, so the operation expects to read 'a' from the Input field, but Input is also empty/whitespace. Without a value there is nothing to invert, so the operation aborts before parsing.","triggerScenarios":"run(input, args) with args[0] (Value) empty/whitespace, args[1] (Modulus) populated, and input empty or whitespace-only. The trim() at line 58 makes '   ' count as empty.","commonSituations":"User clears the Value box intending to feed it via Input but forgets to paste anything into Input; recipe wired so the value is supplied on a different stream than expected; trailing whitespace only.","solutions":["Supply a non-empty Value (a) argument, or put the value in the Input field when Value is blank.","Ensure the input string is not just whitespace — trim() treats it as missing.","If scripting, pass the value through Input and leave Value empty, or vice versa, but never both empty."],"exampleFix":"// before: Value empty, Input empty\nchef.bake(\"Modular Inverse\", [\"\", \"7\"], \"\");\n// after: supply 'a' in Input\nchef.bake(\"Modular Inverse\", [\"\", \"7\"], \"3\");","handlingStrategy":"validation","validationCode":"const aParam = (args[0] ?? \"\").trim();\nconst inputVal = (input ?? \"\").trim();\nif (!aParam && !inputVal) {\n  // do not call Modular Inverse; supply a value first\n}","typeGuard":"const hasValueSource = (aStr, input) =>\n  Boolean((aStr ?? \"\").trim()) || Boolean((input ?? \"\").trim());","tryCatchPattern":"try { chef.bake(\"Modular Inverse\", [\"\", m], input); }\ncatch (e) { if (e.message.startsWith(\"Value (a) must be defined\")) supplyA(); else throw e; }","preventionTips":["Always populate the Value box or ensure Input is non-empty.","Trim whitespace from inputs before relying on them.","Treat '   ' as missing when validating."],"tags":["crypto","modular-arithmetic","argument-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}