{"record":{"id":"74730d5799af0fd6","repo":"thanos-io/thanos","slug":"hash-function-v-is-not-supported","errorCode":null,"errorMessage":"hash function %v is not supported","messagePattern":"hash function (.+?) is not supported","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/metadata/hash.go","lineNumber":62,"sourceCode":"\tcase SHA256Func:\n\t\tf, err := os.Open(filepath.Clean(p))\n\t\tif err != nil {\n\t\t\treturn ObjectHash{}, errors.Wrap(err, \"opening file\")\n\t\t}\n\t\tdefer runutil.CloseWithLogOnErr(logger, f, \"closing %s\", p)\n\n\t\th := sha256.New()\n\n\t\tif _, err := io.Copy(h, f); err != nil {\n\t\t\treturn ObjectHash{}, errors.Wrap(err, \"copying\")\n\t\t}\n\n\t\treturn ObjectHash{\n\t\t\tFunc:  SHA256Func,\n\t\t\tValue: hex.EncodeToString(h.Sum(nil)),\n\t\t}, nil\n\t}\n\treturn ObjectHash{}, fmt.Errorf(\"hash function %v is not supported\", hf)\n\n}\n","sourceCodeStart":44,"sourceCodeEnd":65,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/metadata/hash.go#L44-L65","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nhf := metadata.HashFunc(\"sha512\")\nh, err := metadata.CalculateHash(ctx, bkt, hf, id)\n// after\nhf := metadata.SHA256Func\nh, err := metadata.CalculateHash(ctx, bkt, hf, id)","handlingStrategy":"validation","validationCode":"if hf != metadata.SHA256Func {\n\treturn fmt.Errorf(\"unsupported hash function %v; only %v is supported\", hf, metadata.SHA256Func)\n}\n// proceed with metadata.CalculateHash(ctx, bkt, hf, id)","typeGuard":"func isSupportedHashFunc(hf metadata.HashFunc) bool { return hf == metadata.SHA256Func }","tryCatchPattern":null,"preventionTips":["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."],"tags":["hashing","unsupported-algorithm","metadata","object-storage"],"backgroundTag":"unsupported-enum-value","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}