JuliusBrussee/caveman · error

objectstore: minio client

Error message

objectstore: minio client: %w

What it means

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.

Solutions

  1. Pass endpoint as host:port only (e.g. 'minio:9000'); move the scheme into cfg.UseSSL.
  2. Trim whitespace/slashes and reject empty endpoints at config load.
  3. Log cfg.Endpoint (redacted) when this error occurs to spot the malformed value quickly.

Example fix

// before
cfg.Endpoint = "https://minio.internal:9000" // scheme breaks minio.New
store, err := objectstore.New(cfg)
// after
cfg.Endpoint = "minio.internal:9000"
cfg.UseSSL = true
store, err := objectstore.New(cfg)
Defensive patterns

Strategy: validation

Validate before calling

ep := strings.TrimSpace(cfg.Endpoint)
ep = strings.TrimPrefix(strings.TrimPrefix(ep, "https://"), "http://")
if ep == "" || strings.Contains(ep, "/") {
    return errors.New("endpoint must be host:port without scheme")
}

Type guard

func validMinioEndpoint(ep string) bool {
    ep = strings.TrimSpace(ep)
    return ep != "" && !strings.Contains(ep, "://") && !strings.Contains(ep, "/")
}

Try / catch

store, err := objectstore.New(cfg)
if err != nil && strings.Contains(err.Error(), "minio client") {
    return fmt.Errorf("bad objectstore endpoint %q: %w", cfg.Endpoint, err)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/7f335e24f9e5c845. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/objectstore/objectstore.go:221

		raw = "https://" + raw
	}
	u, err := url.Parse(raw)
	if err != nil || u.Scheme != "https" || u.Hostname() == "" || u.User != nil || u.RawQuery != "" || u.Fragment != "" || (u.Path != "" && u.Path != "/") {
		return errors.New("objectstore: production endpoint must be an HTTPS origin without credentials, path, query, or fragment")
	}
	return nil
}

// New constructs a MinIO/S3-backed Store. FromEnv adds a live production probe.
func New(cfg Config) (Store, error) {
	endpoint := strings.TrimPrefix(strings.TrimPrefix(cfg.Endpoint, "https://"), "http://")
	client, err := minio.New(endpoint, &minio.Options{
		Creds:  credentials.NewStaticV4(cfg.AccessKey, cfg.SecretKey, ""),
		Secure: cfg.UseSSL,
		Region: cfg.Region,
	})
	if err != nil {
		return nil, fmt.Errorf("objectstore: minio client: %w", err)
	}
	return &minioStore{client: client, bucket: cfg.Bucket}, nil
}

// Probe proves the operations production retention needs instead of accepting a
// syntactically valid but unusable bucket configuration. The random probe body
// contains no tenant data and every version is removed before success returns.
func Probe(ctx context.Context, store Store) error {
	if store == nil {
		return errors.New("store is nil")
	}
	probe := make([]byte, 32)
	if _, err := rand.Read(probe); err != nil {
		return fmt.Errorf("generate probe: %w", err)
	}
	key := "_cave_health/" + base64.RawURLEncoding.EncodeToString(probe)
	if err := store.Put(ctx, key, probe, "application/octet-stream"); err != nil {
		return err

View on GitHub (pinned to 3ee70a1026)