{"record":{"id":"7f335e24f9e5c845","repo":"JuliusBrussee/caveman","slug":"objectstore-minio-client-w","errorCode":null,"errorMessage":"objectstore: minio client: %w","messagePattern":"objectstore: minio client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/objectstore/objectstore.go","lineNumber":221,"sourceCode":"\t\traw = \"https://\" + raw\n\t}\n\tu, err := url.Parse(raw)\n\tif err != nil || u.Scheme != \"https\" || u.Hostname() == \"\" || u.User != nil || u.RawQuery != \"\" || u.Fragment != \"\" || (u.Path != \"\" && u.Path != \"/\") {\n\t\treturn errors.New(\"objectstore: production endpoint must be an HTTPS origin without credentials, path, query, or fragment\")\n\t}\n\treturn nil\n}\n\n// New constructs a MinIO/S3-backed Store. FromEnv adds a live production probe.\nfunc 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","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/objectstore/objectstore.go#L203-L239","documentation":"New wraps minio.New client-construction failures with 'objectstore: minio client:'. This only fires when the MinIO SDK itself cannot build a client, which is rare since minio.New mostly validates endpoint syntax — it does not perform network I/O.","triggerScenarios":"Calling objectstore.New with a malformed endpoint (empty string, contains scheme like 'https://', illegal characters, or unparseable host:port) so minio.New returns an error before any request is made.","commonSituations":"Endpoint env var including 'http://'/'https://' prefix when the SDK expects host:port (SSL handled by UseSSL); empty endpoint because the env var is unset and no default applied; trailing slashes or whitespace from config files.","solutions":["Pass endpoint as host:port only (e.g. 'minio:9000'); move the scheme into cfg.UseSSL.","Trim whitespace/slashes and reject empty endpoints at config load.","Log cfg.Endpoint (redacted) when this error occurs to spot the malformed value quickly."],"exampleFix":"// before\ncfg.Endpoint = \"https://minio.internal:9000\" // scheme breaks minio.New\nstore, err := objectstore.New(cfg)\n// after\ncfg.Endpoint = \"minio.internal:9000\"\ncfg.UseSSL = true\nstore, err := objectstore.New(cfg)","handlingStrategy":"validation","validationCode":"ep := strings.TrimSpace(cfg.Endpoint)\nep = strings.TrimPrefix(strings.TrimPrefix(ep, \"https://\"), \"http://\")\nif ep == \"\" || strings.Contains(ep, \"/\") {\n    return errors.New(\"endpoint must be host:port without scheme\")\n}","typeGuard":"func validMinioEndpoint(ep string) bool {\n    ep = strings.TrimSpace(ep)\n    return ep != \"\" && !strings.Contains(ep, \"://\") && !strings.Contains(ep, \"/\")\n}","tryCatchPattern":"store, err := objectstore.New(cfg)\nif err != nil && strings.Contains(err.Error(), \"minio client\") {\n    return fmt.Errorf(\"bad objectstore endpoint %q: %w\", cfg.Endpoint, err)\n}","preventionTips":["Store endpoint as host:port; encode TLS in UseSSL, not the endpoint string.","Trim whitespace and strip accidental scheme prefixes at config load.","Fail fast on empty endpoints with a clear config error."],"tags":["minio","configuration","invalid-url"],"backgroundTag":"invalid-url-format","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"}