{"record":{"id":"b014e7daed69bae9","repo":"gchq/CyberChef","slug":"error-err-message","errorCode":null,"errorMessage":"Error: ${err.message}","messagePattern":"Error: (.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/Argon2.mjs","lineNumber":111,"sourceCode":"                salt,\n                time,\n                mem,\n                parallelism,\n                hashLen,\n                type,\n            });\n\n            switch (outFormat) {\n                case \"Hex hash\":\n                    return result.hashHex;\n                case \"Raw hash\":\n                    return Utils.arrayBufferToStr(result.hash);\n                case \"Encoded hash\":\n                default:\n                    return result.encoded;\n            }\n        } catch (err) {\n            throw new OperationError(`Error: ${err.message}`);\n        }\n    }\n\n}\n\nexport default Argon2;\n","sourceCodeStart":93,"sourceCodeEnd":118,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/Argon2.mjs#L93-L118","documentation":"Generic catch-all thrown by Argon2.run when the underlying argon2 computation rejects the parameters or input. Any exception from the argon2 library (bad salt, invalid memory/time/parallelism parameters, output-format mismatch, or internal hash failure) is rewrapped into OperationError with the original message preserved as 'Error: <original>'. The switch on outFormat handles successful results only, so all error paths funnel through this single catch.","triggerScenarios":"Passing a salt shorter than 8 bytes (argon2 minimum), memory cost (m) below 8 KiB or not a power of two region, time/iterations (t) of 0, parallelism (p) of 0, a password/salt encoding the library cannot decode, or an unsupported outFormat combined with a library that errors during hashing.","commonSituations":"Recipe defaults overridden with too-small salt/memory; user lowers iterations to 0 to speed up hashing; binary salt supplied as a plain UTF-8 string that decodes to too few bytes; argon2 variant mismatch (argon2id params passed to argon2d context).","solutions":["Ensure salt is at least 8 bytes (use Hex or Base64 input option for a binary salt).","Set memory cost (m) >= 8 (KiB), typically >= 16, iterations (t) >= 1, parallelism (p) >= 1.","Read the original message after 'Error: ' in the output for the exact argon2 constraint violated.","Match the argon2 variant (i/d/id) to the parameters you are supplying."],"exampleFix":"// before\nchef.argon2(\"pw\", { salt: \"abc\", m: 4, t: 0, p: 1 });\n\n// after - 16-byte hex salt, valid costs\nchef.argon2(\"pw\", { salt: \"00112233445566778899aabbccddeeff\", m: 16, t: 3, p: 1 });","handlingStrategy":"validation","validationCode":"function assertArgon2Params({ saltBytes, m, t, p }) {\n  if (saltBytes.length < 8) throw new Error(\"salt must be >= 8 bytes\");\n  if (!Number.isInteger(m) || m < 8) throw new Error(\"memory cost m must be >= 8 KiB\");\n  if (!Number.isInteger(t) || t < 1) throw new Error(\"iterations t must be >= 1\");\n  if (!Number.isInteger(p) || p < 1) throw new Error(\"parallelism p must be >= 1\");\n}\nassertArgon2Params({ saltBytes: new Uint8Array(saltDecoded), m, t, p });","typeGuard":"function isValidArgon2Params({ m, t, p }) {\n  return Number.isInteger(m) && m >= 8 && Number.isInteger(t) && t >= 1 && Number.isInteger(p) && p >= 1;\n}","tryCatchPattern":"try {\n  await chef.argon2(pw, opts);\n} catch (e) {\n  if (e.message.startsWith(\"Error:\")) {\n    // argon2 library rejection; surface original reason\n    throw new Error(`argon2 failed: ${e.message.slice(7)}`);\n  }\n  throw e;\n}","preventionTips":["Supply a >=8-byte binary salt via the Hex/Base64 input option.","Keep m >= 8 (KiB), t >= 1, p >= 1.","Match the argon2 variant to the parameters you supply."],"tags":["crypto","kdf","argon2","parameter-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}