thanos-io/thanos · error
hash function is not supported
Error message
hash function %v is not supported
What it means
CalculateHash in pkg/block/metadata only implements a fixed set of object hash functions (currently SHA-256 via SHA256Func). When the caller passes a hash function identifier (hf) that is not one of the supported ones, the function returns this error instead of computing a hash. It is a guard against unsupported enum values for the hash algorithm.
Solutions
- Change the hash function configuration/value to SHA256Func, the only currently supported algorithm.
- Check the Thanos version: metadata written by a newer version with a different hash function needs that version (or later) to be read.
- If you believe the algorithm should be supported, add a case for it in CalculateHash and upstream it; otherwise do not pass arbitrary hash func identifiers.
Example fix
// before
hf := metadata.HashFunc("sha512")
h, err := metadata.CalculateHash(ctx, bkt, hf, id)
// after
hf := metadata.SHA256Func
h, err := metadata.CalculateHash(ctx, bkt, hf, id) Defensive patterns
Strategy: validation
Validate before calling
if hf != metadata.SHA256Func {
return fmt.Errorf("unsupported hash function %v; only %v is supported", hf, metadata.SHA256Func)
}
// proceed with metadata.CalculateHash(ctx, bkt, hf, id) Type guard
func isSupportedHashFunc(hf metadata.HashFunc) bool { return hf == metadata.SHA256Func } Prevention
- Only use exported constants (metadata.SHA256Func) instead of constructing HashFunc values from strings.
- When reading hash funcs from config, validate against the supported set at config load time.
- Pin Thanos versions so producer and consumer agree on the supported hash algorithms.
When it happens
Trigger: Calling metadata.CalculateHash (directly or via Download, GatherFileStats, or block creation in createBlock) with an ObjectHash.Func / HashFunc value other than the supported SHA256Func, e.g. SHA1, SHA512, or a zero value.
Common situations: Config files or metadata JSON produced by newer/older Thanos versions that use a hash algorithm this build does not know; custom tooling writing block meta with a hand-picked hash function; copy-pasted code that hardcodes a different constant than SHA256Func.
Related errors
AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07).
Data as JSON: /api/errors/74730d5799af0fd6.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/block/metadata/hash.go:62
case SHA256Func:
f, err := os.Open(filepath.Clean(p))
if err != nil {
return ObjectHash{}, errors.Wrap(err, "opening file")
}
defer runutil.CloseWithLogOnErr(logger, f, "closing %s", p)
h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
return ObjectHash{}, errors.Wrap(err, "copying")
}
return ObjectHash{
Func: SHA256Func,
Value: hex.EncodeToString(h.Sum(nil)),
}, nil
}
return ObjectHash{}, fmt.Errorf("hash function %v is not supported", hf)
}
View on GitHub (pinned to 35b8b99117)