{"record":{"id":"c03ff29ee231a7cf","repo":"thanos-io/thanos","slug":"check-exists-s-in-bucket","errorCode":null,"errorMessage":"check exists %s in bucket","messagePattern":"check exists (.+?) in bucket","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/block.go","lineNumber":386,"sourceCode":"\n\tmetaFile, err := os.Stat(filepath.Join(blockDir, MetaFilename))\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"stat %v\", filepath.Join(blockDir, MetaFilename))\n\t}\n\tres = append(res, metadata.File{RelPath: metaFile.Name()})\n\n\tsort.Slice(res, func(i, j int) bool {\n\t\treturn strings.Compare(res[i].RelPath, res[j].RelPath) < 0\n\t})\n\treturn res, err\n}\n\n// MarkForNoCompact creates a file which marks block to be not compacted.\nfunc MarkForNoCompact(ctx context.Context, logger log.Logger, bkt objstore.Bucket, id ulid.ULID, reason metadata.NoCompactReason, details string, markedForNoCompact prometheus.Counter) error {\n\tm := path.Join(id.String(), metadata.NoCompactMarkFilename)\n\tnoCompactMarkExists, err := bkt.Exists(ctx, m)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"check exists %s in bucket\", m)\n\t}\n\tif noCompactMarkExists {\n\t\tlevel.Warn(logger).Log(\"msg\", \"requested to mark for no compaction, but file already exists; this should not happen; investigate\", \"err\", errors.Errorf(\"file %s already exists in bucket\", m))\n\t\treturn nil\n\t}\n\n\tnoCompactMark, err := json.Marshal(metadata.NoCompactMark{\n\t\tID:      id,\n\t\tVersion: metadata.NoCompactMarkVersion1,\n\n\t\tNoCompactTime: time.Now().Unix(),\n\t\tReason:        reason,\n\t\tDetails:       details,\n\t})\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"json encode no compact mark\")\n\t}\n","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/block.go#L368-L404","documentation":"MarkForNoCompact first checks whether the no-compact mark file (<blockID>/no-compact-mark.json) already exists in the bucket; this error wraps a failed bkt.Exists call. It indicates the object storage existence check itself failed (network/auth error), not that the mark exists.","triggerScenarios":"bkt.Exists(ctx, id/no-compact-mark.json) returns an error — object storage unreachable, credentials invalid, bucket missing, or context cancelled during the HEAD request.","commonSituations":"Temporary S3/GCS outage; expired credentials (IAM role refresh failure); wrong bucket name in config; context deadline exceeded while marking a block after compaction planning.","solutions":["Retry the operation; Exists failures are usually transient object-store errors.","Verify bucket credentials and that the bucket exists and is accessible.","Check network connectivity/egress to the object storage endpoint.","Check ctx cancellation if timeouts occur consistently."],"exampleFix":"// before\nnoCompactMarkExists, err := bkt.Exists(ctx, m)\nif err != nil {\n\treturn errors.Wrapf(err, \"check exists %s in bucket\", m)\n}\n// after\nnoCompactMarkExists, err := bkt.Exists(ctx, m)\nif err != nil {\n\tif ctx.Err() != nil {\n\t\treturn errors.Wrapf(ctx.Err(), \"check exists %s in bucket: context cancelled\", m)\n\t}\n\treturn errors.Wrapf(err, \"check exists %s in bucket\", m)\n}","handlingStrategy":"retry","validationCode":"if err := ctx.Err(); err != nil { return err }\nif err := bkt.Iter(ctx, \"\", func(string) error { return nil }); err != nil {\n\treturn fmt.Errorf(\"bucket not reachable before mark: %w\", err)\n}","typeGuard":"func bucketReachable(ctx context.Context, bkt objstore.Bucket) bool {\n\treturn bkt.Iter(ctx, \"\", func(string) error { return nil }) == nil\n}","tryCatchPattern":"err := block.MarkForNoCompact(ctx, logger, bkt, id, reason, details, noCompactMarked)\nif err != nil {\n\tif ctx.Err() != nil { return err }\n\t// transient object-store failure: retry with backoff\n\treturn retryWithBackoff(ctx, 3, time.Second, func() error {\n\t\treturn block.MarkForNoCompact(ctx, logger, bkt, id, reason, details, noCompactMarked)\n\t})\n}","preventionTips":["Use retryable HTTP clients / objstore wrappers for transient errors.","Verify bucket credentials and IAM policies before batch marking operations.","Pass contexts with deadlines sized for object-store latency.","Monitor object-store error metrics (thanos_objstore_bucket_operations_failures_total)."],"tags":["object-storage","network","thanos"],"backgroundTag":"http-request-failed","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"}