{"record":{"id":"bd193ff3ca67484c","repo":"gchq/CyberChef","slug":"value-a-must-be-defined","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/ExtendedGCD.mjs","lineNumber":73,"sourceCode":"    run(input, args) {\n        const [aStr, bStr] = args;\n\n        // Trim everything so \"\" and \"   \" count as empty\n        const aParam = aStr?.trim();\n        const bParam = bStr?.trim();\n        const inputVal = input?.trim();\n\n        let a, b;\n\n        if (aParam && bParam) {\n            // Case 1: both values given as parameters\n            a = aParam;\n            b = bParam;\n        } else if (!aParam && bParam) {\n            // Case 2: a missing - take from input\n            a = inputVal;\n            b = bParam;\n            if (!a) throw new OperationError(\"Value a must be defined\");\n        } else if (aParam && !bParam) {\n            // Case 3: b missing - take from input\n            a = aParam;\n            b = inputVal;\n            if (!b) throw new OperationError(\"Value b must be defined\");\n        } else if (!aParam && !bParam) {\n            // Case 4: both values missing\n            throw new OperationError(\"Values a and b must be defined\");\n        }\n\n        const aBI = parseBigInt(a, \"Value a\");\n        const bBI = parseBigInt(b, \"Value b\");\n\n        const [g, x, y] = egcd(aBI, bBI);\n        const gcd = g < 0n ? -g : g;\n\n        // Format output string bearing in mind that crypto-grade numbers\n        // may greatly exceed the line length.","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ExtendedGCD.mjs#L55-L91","documentation":"Thrown by the Extended GCD operation when computing the Extended Euclidean Algorithm. The operation accepts values a and b either as arguments or falls back to the input field. This specific error fires when 'Value a' is left blank as a parameter AND the input field is also empty or whitespace, while 'Value b' was provided. The operation cannot compute gcd(a,b) without a value for a.","triggerScenarios":"run(input, args) where args[0] ('Value a') is empty/whitespace, args[1] ('Value b') is non-empty, and the input string (inputVal = input?.trim()) is also empty/whitespace. Specifically the !aParam && bParam branch at line 69 where inputVal is falsy.","commonSituations":"User provides only Value b in the arguments panel and forgets to type a number into either Value a or the Input field. Also occurs when the input field contains only whitespace characters that get trimmed to empty.","solutions":["Enter a numeric value in the 'Value a' argument field.","Alternatively, enter a numeric value in the Input field (it will be used as Value a when the argument is blank).","Ensure the value is a valid integer string (decimal or hex) accepted by parseBigInt."],"exampleFix":"// before: args = ['', '48'], input = ''\n// Value a blank, input blank -> error\n\n// after: args = ['36', '48'], input = ''\n// Both values supplied as arguments\n// or: args = ['', '48'], input = '36'\n// a taken from input","handlingStrategy":"validation","validationCode":"// Before calling ExtendedGCD, ensure Value a is available\nconst aParam = (args[0] || '').trim();\nconst inputVal = (input || '').trim();\nif (!aParam && !inputVal) {\n  // prompt user or supply default\n  throw new Error('Value a must be provided via argument or input');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always populate at least one source for each operand (argument or input).","Trim and check inputs before passing to the operation.","Validate that values are non-empty numeric strings before running."],"tags":["validation","number-theory","argument-required"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}