{"record":{"id":"379967f23d70c268","repo":"thanos-io/thanos","slug":"errinvalidbucketcachekeyformat","errorCode":"ErrInvalidBucketCacheKeyFormat","errorMessage":"key has invalid format","messagePattern":"key has invalid format","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/store/cache/cachekey/cachekey.go","lineNumber":14,"sourceCode":"// Copyright (c) The Thanos Authors.\n// Licensed under the Apache License 2.0.\n\npackage cachekey\n\nimport (\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/pkg/errors\"\n)\n\nvar (\n\tErrInvalidBucketCacheKeyFormat = errors.New(\"key has invalid format\")\n\tErrInvalidBucketCacheKeyVerb   = errors.New(\"key has invalid verb\")\n\tErrParseKeyInt                 = errors.New(\"failed to parse integer in key\")\n)\n\n// VerbType is the type of operation whose result has been stored in the caching bucket's cache.\ntype VerbType string\n\nconst (\n\tExistsVerb        VerbType = \"exists\"\n\tContentVerb       VerbType = \"content\"\n\tIterVerb          VerbType = \"iter\"\n\tIterRecursiveVerb VerbType = \"iter-recursive\"\n\tAttributesVerb    VerbType = \"attrs\"\n\tSubrangeVerb      VerbType = \"subrange\"\n)\n\ntype BucketCacheKey struct {\n\tVerb                    VerbType","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/cache/cachekey/cachekey.go#L1-L32","documentation":"ParseBucketCacheKey splits a cache key on ':' and requires at least two parts (verb and name). If the key has fewer than two colon-separated fields, it cannot represent a cached bucket operation and ErrInvalidBucketCacheKeyFormat is returned. This indicates a malformed cache entry key, usually produced by a different version of the key format.","triggerScenarios":"Calling ParseBucketCacheKey with a key string containing no ':' (strings.Split yields len(slice) < 2), e.g. \"randomname\" instead of \"subrange:name:start:end\".","commonSituations":"Stale or hand-crafted cache entries left over from an older Thanos version that used a different key format; external tools writing cache keys; corrupted cache backends (e.g. memcached/in-memory cache seeded with wrong keys).","solutions":["Clear the bucket cache so all keys are regenerated in the current format.","Verify the cache key producer uses the current VerbType:name[:start:end] format.","Check for mixed Thanos versions sharing one cache backend and align them.","If parsing user input, validate the key contains at least one ':' before calling ParseBucketCacheKey."],"exampleFix":"// before\nck, err := cachekey.ParseBucketCacheKey(\"randomname\")\n// after\nif !strings.Contains(key, \":\") {\n    return fmt.Errorf(\"skipping malformed cache key %q\", key)\n}\nck, err := cachekey.ParseBucketCacheKey(key)","handlingStrategy":"validation","validationCode":"if !strings.Contains(key, \":\") {\n    return nil, fmt.Errorf(\"skip malformed cache key %q\", key)\n}","typeGuard":"func looksLikeCacheKey(key string) bool {\n    return strings.Count(key, \":\") >= 1\n}","tryCatchPattern":"ck, err := cachekey.ParseBucketCacheKey(key)\nif err != nil {\n    if errors.Is(err, cachekey.ErrInvalidBucketCacheKeyFormat) {\n        continue // skip malformed entry\n    }\n    return err\n}","preventionTips":["Always validate key shape before parsing cache entries","Flush caches after upgrading key formats between versions","Never share one cache backend across incompatible versions","Treat parse errors on cache reads as skip-worthy, not fatal"],"tags":["go","cache","key-format","parsing"],"backgroundTag":"invalid-argument-format","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"}