{"record":{"id":"658d93231ac7fa50","repo":"thanos-io/thanos","slug":"bucket-is-nil","errorCode":null,"errorMessage":"bucket is nil","messagePattern":"bucket is nil","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/cache/caching_bucket.go","lineNumber":58,"sourceCode":"\tobjstore.Bucket\n\n\tcfg    *cache.CachingBucketConfig\n\tlogger log.Logger\n\n\trequestedGetRangeBytes *prometheus.CounterVec\n\tfetchedGetRangeBytes   *prometheus.CounterVec\n\trefetchedGetRangeBytes *prometheus.CounterVec\n\n\toperationConfigs  map[string][]*cache.OperationConfig\n\toperationRequests *prometheus.CounterVec\n\toperationHits     *prometheus.CounterVec\n}\n\n// NewCachingBucket creates new caching bucket with provided configuration. Configuration should not be\n// changed after creating caching bucket.\nfunc NewCachingBucket(b objstore.Bucket, cfg *cache.CachingBucketConfig, logger log.Logger, reg prometheus.Registerer) (*CachingBucket, error) {\n\tif b == nil {\n\t\treturn nil, errors.New(\"bucket is nil\")\n\t}\n\n\tcb := &CachingBucket{\n\t\tBucket: b,\n\t\tcfg:    cfg,\n\t\tlogger: logger,\n\n\t\toperationConfigs: map[string][]*cache.OperationConfig{},\n\n\t\trequestedGetRangeBytes: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{\n\t\t\tName: \"thanos_store_bucket_cache_getrange_requested_bytes_total\",\n\t\t\tHelp: \"Total number of bytes requested via GetRange.\",\n\t\t}, []string{\"config\"}),\n\t\tfetchedGetRangeBytes: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{\n\t\t\tName: \"thanos_store_bucket_cache_getrange_fetched_bytes_total\",\n\t\t\tHelp: \"Total number of bytes fetched because of GetRange operation. Data from bucket is then stored to cache.\",\n\t\t}, []string{\"origin\", \"config\"}),\n\t\trefetchedGetRangeBytes: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/cache/caching_bucket.go#L40-L76","documentation":"NewCachingBucket validates that a non-nil objstore.Bucket is supplied before wrapping it. Passing nil would leave CachingBucket with a nil embedded Bucket that panics on first use, so the constructor fails fast with \"bucket is nil\".","triggerScenarios":"Calling NewCachingBucket(nil, cfg, logger, reg), typically when a bucket client construction step upstream returned (nil, nil) or a nil bucket was propagated from a factory/config lookup.","commonSituations":"Misconfigured bucket client YAML silently producing a nil bucket; ignoring an error from an earlier bucket-constructor call; tests wiring a caching bucket without an underlying bucket.","solutions":["Check the error from the underlying bucket client constructor before passing the bucket to NewCachingBucket.","Log/inspect the bucket factory result; ensure the objstore provider (s3/gcs/etc.) config is valid and non-nil.","In tests, always build a real or in-memory objstore.Bucket (e.g. objstore.NewInMemBucket) rather than passing nil.","Fail startup early with a clear message when bucket construction yields nil."],"exampleFix":"// before\nbkt, _ := objstore.NewClient(ctx, logger, cfg, reg)\ncb, err := cache.NewCachingBucket(bkt, cacheCfg, logger, reg)\n// after\nbkt, err := objstore.NewClient(ctx, logger, cfg, reg)\nif err != nil {\n    return errors.Wrap(err, \"build bucket client\")\n}\ncb, err := cache.NewCachingBucket(bkt, cacheCfg, logger, reg)","handlingStrategy":"validation","validationCode":"if bkt == nil {\n    return errors.New(\"underlying bucket client is nil; check bucket config\")\n}\ncb, err := cache.NewCachingBucket(bkt, cacheCfg, logger, reg)","typeGuard":"func bucketReady(b objstore.Bucket) bool { return b != nil }","tryCatchPattern":"cb, err := cache.NewCachingBucket(bkt, cacheCfg, logger, reg)\nif err != nil {\n    return errors.Wrap(err, \"create caching bucket\") // includes 'bucket is nil'\n}","preventionTips":["Check every upstream constructor's error before using its result","Never ignore the error return when building bucket clients","Build real/in-memory buckets in tests instead of nil","Fail fast at startup when the bucket is nil"],"tags":["go","nil-check","object-store","configuration"],"backgroundTag":"null-argument","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"}