Files
minio/errors.go
Rene Nochebuena 3d12d18200 feat(minio): initial stable release v1.0.0 — Client interface, xerrors, GetObject, doc examples
Add Client interface with PutObject, GetObject, RemoveObject, PresignedGetObject, and
HandleError; Component now embeds Client with Native() as escape hatch for operations
not covered by the interface. Add xerrors dependency: HandleError maps minio-go error
codes to portable typed codes (NoSuchKey → ErrNotFound, AccessDenied →
ErrPermissionDenied, BucketAlreadyExists → ErrAlreadyExists, etc.). OnStop sets
c.mc = nil for lifecycle consistency. doc.go updated with launcher wiring, upload,
presigned URL, GetObject, and HandleError usage examples. API committed as stable.

What's included:
- Config with Endpoint, AccessKey, SecretKey, UseSSL, Bucket, Region (env-driven, embeddable)
- Transport field in Config for test injection (env:"-", nil uses minio-go default)
- Client interface: PutObject, GetObject, RemoveObject, PresignedGetObject, HandleError
- Component interface: launcher.Component + health.Checkable + Client + Native()
- New(logger, cfg) constructor for lifecycle registration via lc.Append
- Automatic bucket creation on OnStart if bucket does not exist
- Health check via BucketExists at LevelCritical priority
- HandleError: maps minio-go ErrorResponse codes to xerrors typed errors
- 21 unit tests using mock HTTP transport; no live server required
2026-05-19 21:42:30 -06:00

28 lines
918 B
Go

package minio
import (
miniogo "github.com/minio/minio-go/v7"
"code.nochebuena.dev/go/xerrors"
)
// HandleError maps minio-go errors to xerrors types.
// Also available as client.HandleError(err).
func HandleError(err error) error {
if err == nil {
return nil
}
resp := miniogo.ToErrorResponse(err)
switch resp.Code {
case miniogo.NoSuchBucket:
return xerrors.New(xerrors.ErrNotFound, "bucket not found").WithError(err)
case miniogo.NoSuchKey:
return xerrors.New(xerrors.ErrNotFound, "object not found").WithError(err)
case miniogo.AccessDenied, miniogo.InvalidAccessKeyID:
return xerrors.New(xerrors.ErrPermissionDenied, "access denied").WithError(err)
case miniogo.BucketAlreadyExists, miniogo.BucketAlreadyOwnedByYou:
return xerrors.New(xerrors.ErrAlreadyExists, "bucket already exists").WithError(err)
}
return xerrors.New(xerrors.ErrInternal, "unexpected storage error").WithError(err)
}