{"record":{"id":"4702c18d2c77f9fc","repo":"gohugoio/hugo","slug":"q-is-not-a-supported-encoding-method","errorCode":null,"errorMessage":"%q is not a supported encoding method","messagePattern":"%q is not a supported encoding method","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/crypto/crypto.go","lineNumber":178,"sourceCode":"\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tencoding := \"hex\"\n\tif len(e) > 0 && e[0] != nil {\n\t\tencoding, err = cast.ToStringE(e[0])\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t}\n\n\tswitch encoding {\n\tcase \"binary\":\n\t\treturn string(mac.Sum(nil)[:]), nil\n\tcase \"hex\":\n\t\treturn hex.EncodeToString(mac.Sum(nil)[:]), nil\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"%q is not a supported encoding method\", encoding)\n\t}\n}\n","sourceCodeStart":160,"sourceCodeEnd":181,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/crypto/crypto.go#L160-L181","documentation":"`crypto.HMAC` accepts an optional fourth argument selecting output encoding (crypto.go:164-179). After defaulting to `hex`, it matches only `binary` or `hex`; any other value reaches the `default` arm and returns this error quoting the unsupported encoding.","triggerScenarios":"`{{ crypto.HMAC \"sha256\" $key $msg \"base64\" }}` (base64 not supported), `{{ crypto.HMAC ... \"HEX\" }}` (uppercase), or a typo.","commonSituations":"Expecting base64 output (common for tokens/signatures); passing uppercase; copy-pasting an encoding name from a different library.","solutions":["Use `hex` (default) or `binary` as the encoding argument.","For base64, take the hex output and apply `encoding.Base64Encode` on the decoded bytes, or compute in Go.","Omit the encoding argument to get hex."],"exampleFix":"// before\n{{ crypto.HMAC \"sha256\" $key $msg \"base64\" }}\n// after\n{{ crypto.HMAC \"sha256\" $key $msg \"hex\" }}\n{{ crypto.HMAC \"sha256\" $key $msg }}","handlingStrategy":"validation","validationCode":"{{/* Valid encodings: hex (default), binary */}}\n{{ crypto.HMAC \"sha256\" $key $msg }}\n{{ crypto.HMAC \"sha256\" $key $msg \"binary\" }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only `hex` or `binary` for the encoding argument.","Omit the arg entirely for hex output.","Post-process hex output for base64 in a separate step if needed."],"tags":["hugo","go-templates","crypto","hmac","encoding","invalid-argument"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}