{"record":{"id":"0049ac74fc2b27d1","repo":"denoland/deno","slug":"err-invalid-arg-value-0049ac","errorCode":"ERR_INVALID_ARG_VALUE","errorMessage":"The argument 'outputEncoding' is invalid. Received ${inspected}","messagePattern":"The argument 'outputEncoding' is invalid\\. Received (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/crypto.ts","lineNumber":173,"sourceCode":"  if (typeof outputEncodingOrOptions === \"object\") {\n    outputEncoding = outputEncodingOrOptions.outputEncoding ?? \"hex\";\n    outputLength = outputEncodingOrOptions.outputLength;\n  } else {\n    outputEncoding = outputEncodingOrOptions;\n  }\n\n  let normalized = outputEncoding;\n  // Fast case: if it's 'hex', we don't need to validate it further.\n  if (outputEncoding !== \"hex\") {\n    validateString(outputEncoding, \"outputEncoding\");\n    normalized = normalizeEncoding(outputEncoding);\n    // If the encoding is invalid, normalizeEncoding() returns undefined.\n    if (normalized === undefined) {\n      // normalizeEncoding() doesn't handle 'buffer'.\n      if (StringPrototypeToLowerCase(outputEncoding) === \"buffer\") {\n        normalized = \"buffer\";\n      } else {\n        throw new ERR_INVALID_ARG_VALUE(\"outputEncoding\", outputEncoding);\n      }\n    }\n  }\n\n  const algoLower = StringPrototypeToLowerCase(algorithm);\n  const isXof = algoLower === \"shake128\" || algoLower === \"shake256\";\n\n  if (outputLength != null && !isXof) {\n    // For non-XOF hashes, outputLength must match the algorithm's digest size.\n    const testHash = createHash(algorithm);\n    testHash.update(\"\");\n    const expectedLen = testHash.digest().length;\n    if (outputLength !== expectedLen) {\n      throw new Error(\n        `Output length ${outputLength} is invalid for ${algoLower}, which does not support XOF`,\n      );\n    }\n  }","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/crypto.ts#L155-L191","documentation":"crypto.hash's outputEncoding (the third argument as a string, or the outputEncoding field of the options object) must name a known encoding. It is normalized like Buffer encodings; when normalizeEncoding() returns undefined only the special value 'buffer' (matched case-insensitively via toLowerCase) is rescued — every other unknown name throws ERR_INVALID_ARG_VALUE.","triggerScenarios":"crypto.hash('sha256', 'x', 'base62'); 'hexadecimal'; 'utf8 ' with trailing space; '' (empty string). The fast path skips validation only for the exact string 'hex'; everything else goes through normalizeEncoding.","commonSituations":"Typos in config-driven encoding names; assuming custom encodings like 'base62' or 'ascii85' exist; casing is forgiving ('BUFFER' works) but spelling and whitespace are not.","solutions":["Use a supported encoding: 'hex', 'base64', 'base64url', 'utf8'/'utf-8', 'utf16le', 'latin1', 'ascii', 'binary'","Pass 'buffer' (any case) to get a Buffer back","Validate encoding names against an allowlist before calling"],"exampleFix":"// before\ncrypto.hash(\"sha256\", \"x\", \"base62\");\n// after\ncrypto.hash(\"sha256\", \"x\", \"base64url\");","handlingStrategy":"validation","validationCode":"const OK_ENCODINGS = new Set([\n  \"hex\", \"base64\", \"base64url\", \"utf8\", \"utf-8\", \"utf16le\",\n  \"latin1\", \"ascii\", \"binary\", \"buffer\",\n]);\nconst enc = String(encoding).toLowerCase();\nif (!OK_ENCODINGS.has(enc)) throw new TypeError(`unsupported encoding: ${encoding}`);","typeGuard":"const isOutputEncoding = (e) => typeof e === \"string\" && OK_ENCODINGS.has(e.toLowerCase());","tryCatchPattern":"try { return crypto.hash(algo, data, enc); }\ncatch (e) {\n  if (e.code === \"ERR_INVALID_ARG_VALUE\" && e.message.includes(\"outputEncoding\")) {\n    return crypto.hash(algo, data, \"hex\");\n  } else throw e;\n}","preventionTips":["Restrict config-driven encoding names to the Node encoding set","Default to 'hex' when unsure","Trim whitespace around encoding values from config files"],"tags":["crypto","hash","encoding","arguments"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}