From 6e4bf2f025d34b4ae8ead5e8f60662dfe5b390ab Mon Sep 17 00:00:00 2001 From: William Petit Date: Sun, 22 Oct 2023 23:04:56 +0200 Subject: [PATCH] feat(storage): remap rpc errors --- pkg/storage/driver/rpc/client/blob_store.go | 2 +- .../driver/rpc/client/document_store.go | 2 +- pkg/storage/driver/rpc/client/error.go | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pkg/storage/driver/rpc/client/blob_store.go b/pkg/storage/driver/rpc/client/blob_store.go index ea3624f..5a62aae 100644 --- a/pkg/storage/driver/rpc/client/blob_store.go +++ b/pkg/storage/driver/rpc/client/blob_store.go @@ -63,7 +63,7 @@ func (s *BlobStore) OpenBucket(ctx context.Context, name string) (storage.BlobBu func (s *BlobStore) call(ctx context.Context, serviceMethod string, args any, reply any) error { err := s.withClient(ctx, func(ctx context.Context, client *rpc.Client) error { if err := client.Call(ctx, serviceMethod, args, reply); err != nil { - return errors.WithStack(err) + return errors.WithStack(remapBlobError(err)) } return nil diff --git a/pkg/storage/driver/rpc/client/document_store.go b/pkg/storage/driver/rpc/client/document_store.go index f1aaf45..b0aaee3 100644 --- a/pkg/storage/driver/rpc/client/document_store.go +++ b/pkg/storage/driver/rpc/client/document_store.go @@ -96,7 +96,7 @@ func (s *DocumentStore) Upsert(ctx context.Context, collection string, doc stora func (s *DocumentStore) call(ctx context.Context, serviceMethod string, args any, reply any) error { err := s.withClient(ctx, func(ctx context.Context, client *rpc.Client) error { if err := client.Call(ctx, serviceMethod, args, reply); err != nil { - return errors.WithStack(err) + return errors.WithStack(remapDocumentError(err)) } return nil diff --git a/pkg/storage/driver/rpc/client/error.go b/pkg/storage/driver/rpc/client/error.go index d505346..0f58f44 100644 --- a/pkg/storage/driver/rpc/client/error.go +++ b/pkg/storage/driver/rpc/client/error.go @@ -1,10 +1,31 @@ package client import ( + "forge.cadoles.com/arcad/edge/pkg/storage" "forge.cadoles.com/arcad/edge/pkg/storage/share" "github.com/pkg/errors" ) +func remapBlobError(err error) error { + switch errors.Cause(err).Error() { + case storage.ErrBlobNotFound.Error(): + return storage.ErrBlobNotFound + case storage.ErrBucketClosed.Error(): + return storage.ErrBucketClosed + default: + return err + } +} + +func remapDocumentError(err error) error { + switch errors.Cause(err).Error() { + case storage.ErrDocumentNotFound.Error(): + return storage.ErrDocumentNotFound + default: + return err + } +} + func remapShareError(err error) error { switch errors.Cause(err).Error() { case share.ErrAttributeRequired.Error():