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

  1. Use "hex" or "binary" — those are the only supported encodings; "hex" is the default, so you can usually omit the argument.
  2. For a base64 signature, request binary output and encode it: `{{ hmac "sha256" $key $msg "binary" | base64Encode }}`.
  3. 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

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


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/4702c18d2c77f9fc.json. Report an issue: GitHub ↗.