gohugoio/hugo · error
%q is not a supported encoding method
Error message
%q is not a supported encoding method
What it means
`hmac` takes an optional fourth argument selecting the output encoding of the MAC. Only `"hex"` (the default) and `"binary"` are accepted; any other value — including common expectations like `"base64"` — hits the switch default and returns this error after the MAC has been computed.
Source
Thrown at tpl/crypto/crypto.go:178
if err != nil {
return "", err
}
encoding := "hex"
if len(e) > 0 && e[0] != nil {
encoding, err = cast.ToStringE(e[0])
if err != nil {
return "", err
}
}
switch encoding {
case "binary":
return string(mac.Sum(nil)[:]), nil
case "hex":
return hex.EncodeToString(mac.Sum(nil)[:]), nil
default:
return "", fmt.Errorf("%q is not a supported encoding method", encoding)
}
}
View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Use "hex" or "binary" — those are the only supported encodings; "hex" is the default, so you can usually omit the argument.
- For a base64 signature, request binary output and encode it: `{{ hmac "sha256" $key $msg "binary" | base64Encode }}`.
- Remove the fourth argument entirely if hex output is acceptable.
Example fix
<!-- before -->
{{ hmac "sha256" $key $msg "base64" }}
<!-- after -->
{{ hmac "sha256" $key $msg "binary" | base64Encode }} Defensive patterns
Strategy: validation
Validate before calling
{{ $enc := "hex" }}
{{ if in (slice "hex" "binary") $enc }}{{ hmac "sha256" $secret $msg $enc }}{{ end }} Prevention
- Only pass supported encoding values (e.g. "hex", "binary") as the optional 4th hmac argument
- Omit the encoding argument to get the default hex output
- Validate encoding strings from site config before use
When it happens
Trigger: `{{ hmac "sha256" $key $msg "base64" }}`; `{{ hmac "sha256" $key $msg "Hex" }}` (case-sensitive); passing a non-encoding value as the fourth argument by mistake.
Common situations: Provider docs (Slack, AWS, payment gateways) that specify base64-encoded signatures — developers pass "base64" expecting it to work; extra trailing arguments left over from refactoring; templating the encoding from config with a typo.
Related errors
- crypto.Hash: expected 1 or 2 arguments, got %d
- crypto.Hash: %q is not a supported hash algorithm
- hmac: %s is not a supported hash function
- error building site: %w
- failed to detect format from content
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/4702c18d2c77f9fc.json.
Report an issue: GitHub ↗.