satellite/metainfo: hardcode the prefix
This avoids a potential bug with regards to not returning the prefix that the uplink expects. Change-Id: I64683db57c5b22989db91b4f8e08530bf3b64ff1
This commit is contained in:
parent
8a206f0aee
commit
511d74a76d
@ -6,6 +6,7 @@ package metainfo
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jtolio/eventkit"
|
"github.com/jtolio/eventkit"
|
||||||
@ -303,9 +304,15 @@ func (endpoint *Endpoint) convertMetabaseErr(err error) error {
|
|||||||
|
|
||||||
switch {
|
switch {
|
||||||
case metabase.ErrObjectNotFound.Has(err):
|
case metabase.ErrObjectNotFound.Has(err):
|
||||||
return rpcstatus.Error(rpcstatus.NotFound, err.Error())
|
message := strings.TrimPrefix(err.Error(), string(metabase.ErrObjectNotFound))
|
||||||
|
message = strings.TrimPrefix(message, ": ")
|
||||||
|
// uplink expects a message that starts with the specified prefix
|
||||||
|
return rpcstatus.Error(rpcstatus.NotFound, "object not found: "+message)
|
||||||
case metabase.ErrSegmentNotFound.Has(err):
|
case metabase.ErrSegmentNotFound.Has(err):
|
||||||
return rpcstatus.Error(rpcstatus.NotFound, err.Error())
|
message := strings.TrimPrefix(err.Error(), string(metabase.ErrSegmentNotFound))
|
||||||
|
message = strings.TrimPrefix(message, ": ")
|
||||||
|
// uplink expects a message that starts with the specified prefix
|
||||||
|
return rpcstatus.Error(rpcstatus.NotFound, "segment not found: "+message)
|
||||||
case metabase.ErrInvalidRequest.Has(err):
|
case metabase.ErrInvalidRequest.Has(err):
|
||||||
return rpcstatus.Error(rpcstatus.InvalidArgument, err.Error())
|
return rpcstatus.Error(rpcstatus.InvalidArgument, err.Error())
|
||||||
case metabase.ErrObjectAlreadyExists.Has(err):
|
case metabase.ErrObjectAlreadyExists.Has(err):
|
||||||
|
35
satellite/metainfo/endpoint_internal_test.go
Normal file
35
satellite/metainfo/endpoint_internal_test.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (C) 2023 Storj Labs, Inc.
|
||||||
|
// See LICENSE for copying information.
|
||||||
|
|
||||||
|
package metainfo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/zeebo/errs"
|
||||||
|
"go.uber.org/zap/zaptest"
|
||||||
|
|
||||||
|
"storj.io/storj/satellite/metabase"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestEndpoint_ConvertMetabaseErr(t *testing.T) {
|
||||||
|
endpoint := &Endpoint{log: zaptest.NewLogger(t)}
|
||||||
|
|
||||||
|
type test struct {
|
||||||
|
err error
|
||||||
|
expect string
|
||||||
|
}
|
||||||
|
|
||||||
|
wrapClass := errs.Class("wrap")
|
||||||
|
|
||||||
|
for _, tc := range []test{
|
||||||
|
{err: metabase.ErrObjectNotFound.New("sql"), expect: "object not found: sql"},
|
||||||
|
{err: wrapClass.Wrap(metabase.ErrObjectNotFound.New("sql")), expect: "object not found: wrap: object not found: sql"},
|
||||||
|
{err: metabase.ErrSegmentNotFound.New("sql"), expect: "segment not found: sql"},
|
||||||
|
{err: wrapClass.Wrap(metabase.ErrSegmentNotFound.New("sql")), expect: "segment not found: wrap: segment not found: sql"},
|
||||||
|
} {
|
||||||
|
out := endpoint.convertMetabaseErr(tc.err)
|
||||||
|
assert.Equal(t, tc.expect, out.Error())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user