{"record":{"id":"a85ae81c529a3e53","repo":"JuliusBrussee/caveman","slug":"store-is-nil","errorCode":null,"errorMessage":"store is nil","messagePattern":"store is nil","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/objectstore/objectstore.go","lineNumber":231,"sourceCode":"func New(cfg Config) (Store, error) {\n\tendpoint := strings.TrimPrefix(strings.TrimPrefix(cfg.Endpoint, \"https://\"), \"http://\")\n\tclient, err := minio.New(endpoint, &minio.Options{\n\t\tCreds:  credentials.NewStaticV4(cfg.AccessKey, cfg.SecretKey, \"\"),\n\t\tSecure: cfg.UseSSL,\n\t\tRegion: cfg.Region,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"objectstore: minio client: %w\", err)\n\t}\n\treturn &minioStore{client: client, bucket: cfg.Bucket}, nil\n}\n\n// Probe proves the operations production retention needs instead of accepting a\n// syntactically valid but unusable bucket configuration. The random probe body\n// contains no tenant data and every version is removed before success returns.\nfunc Probe(ctx context.Context, store Store) error {\n\tif store == nil {\n\t\treturn errors.New(\"store is nil\")\n\t}\n\tprobe := make([]byte, 32)\n\tif _, err := rand.Read(probe); err != nil {\n\t\treturn fmt.Errorf(\"generate probe: %w\", err)\n\t}\n\tkey := \"_cave_health/\" + base64.RawURLEncoding.EncodeToString(probe)\n\tif err := store.Put(ctx, key, probe, \"application/octet-stream\"); err != nil {\n\t\treturn err\n\t}\n\tcleaned := false\n\tdefer func() {\n\t\tif !cleaned {\n\t\t\t// Keep health checks within their caller deadline. A failed probe may\n\t\t\t// leave one random, tenant-free canary for lifecycle cleanup; readiness\n\t\t\t// must never hang on an unbounded background delete.\n\t\t\t_ = PurgeObject(ctx, store, key)\n\t\t}\n\t}()","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/objectstore/objectstore.go#L213-L249","documentation":"Probe verifies a bucket actually supports the operations production retention needs (write, read, version purge) before the service trusts the configuration. It returns 'store is nil' when handed a nil Store — typically because FromEnv returned (nil, nil) in non-production with no S3_ENDPOINT, and the caller passed that straight to Probe.","triggerScenarios":"Calling Probe(ctx, nil); calling Probe on the result of FromEnv when FromEnv returned nil, nil (no S3_ENDPOINT outside production); a Store interface variable that was never assigned due to an earlier error being ignored.","commonSituations":"Bootstrapping code that does store, _ := objectstore.FromEnv() and unconditionally probes in dev environments; forgetting to skip the health probe when no store is configured; nil from a failed constructor swallowed by `_`.","solutions":["Skip the probe when no store is configured: check store == nil (or handle FromEnv's (nil, nil)) before calling Probe.","Check and propagate the error return of FromEnv/New instead of discarding it.","In production, ensure S3_ENDPOINT is set so FromEnv never legitimately returns a nil store.","Wire the store through a constructor that fails fast on nil instead of passing raw interface values."],"exampleFix":"// before\nstore, _ := objectstore.FromEnv()\nif err := objectstore.Probe(ctx, store); err != nil { ... }\n// after\nstore, err := objectstore.FromEnv()\nif err != nil { return err }\nif store != nil {\n    if err := objectstore.Probe(ctx, store); err != nil { return err }\n}","handlingStrategy":"type-guard","validationCode":"if store == nil {\n    return errors.New(\"object store not configured; skipping probe\")\n}","typeGuard":"func storeConfigured(s objectstore.Store) bool { return s != nil }","tryCatchPattern":"if store != nil {\n    if err := objectstore.Probe(ctx, store); err != nil {\n        return fmt.Errorf(\"object store probe: %w\", err)\n    }\n}","preventionTips":["Never discard FromEnv/New error returns with _","Skip health probes when no store is intentionally configured (non-production, no S3_ENDPOINT)","Fail fast at startup when a nil store would be used later"],"tags":["objectstore","nil","validation"],"backgroundTag":"null-argument","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}