grafana/k6 · error
invalid algorithm: %s
Error message
invalid algorithm: %s
What it means
Returned by createHMAC when parseHashFunc returns nil for the requested algorithm — a sentinel-style guard where '%s' names the unsupported algorithm string. It fires before any HMAC work begins, when the algorithm passed to crypto.hmac() is not one of the supported digest names (e.g. a typo like 'sha-256' instead of 'sha256', or an unsupported algorithm like 'ripemd160' which is digest-only).
Source
Thrown at internal/js/modules/k6/crypto/crypto.go:169
return hasher.Digest(outputEncoding)
}
// hexEncode returns a string with the hex representation of the provided byte
// array or ArrayBuffer.
func (c *Crypto) hexEncode(data any) (string, error) {
d, err := common.ToBytes(data)
if err != nil {
return "", err
}
return hex.EncodeToString(d), nil
}
// createHMAC returns a new HMAC hash using the given algorithm and key.
func (c *Crypto) createHMAC(algorithm string, key any) (*Hasher, error) {
h := c.parseHashFunc(algorithm)
if h == nil {
return nil, fmt.Errorf("invalid algorithm: %s", algorithm)
}
kb, err := common.ToBytes(key)
if err != nil {
return nil, err
}
return &Hasher{runtime: c.vu.Runtime(), hash: hmac.New(h, kb)}, nil
}
// HMAC returns a new HMAC hash of input using the given algorithm and key
// in the given encoding.
func (c *Crypto) hmac(algorithm string, key, input any, outputEncoding string) (any, error) {
hasher, err := c.createHMAC(algorithm, key)
if err != nil {
return nil, err
}
err = hasher.Update(input)
if err != nil {View on GitHub (pinned to 01ffac6f24)
Solutions
- Use a supported algorithm: md4, md5, sha1, sha256, sha384, or sha512
- Check for typos and hyphenated names (sha-256 is invalid; use sha256)
- Note ripemd160 is available for digests but not for HMAC in this module
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/crypto/crypto.go:169 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/8816b9868b4e16fd.
Report an issue: GitHub.