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:
Egon Elbre 2023-05-02 12:47:56 +03:00
parent 8a206f0aee
commit 511d74a76d
2 changed files with 44 additions and 2 deletions

View File

@ -6,6 +6,7 @@ package metainfo
import (
"context"
"fmt"
"strings"
"time"
"github.com/jtolio/eventkit"
@ -303,9 +304,15 @@ func (endpoint *Endpoint) convertMetabaseErr(err error) error {
switch {
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):
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):
return rpcstatus.Error(rpcstatus.InvalidArgument, err.Error())
case metabase.ErrObjectAlreadyExists.Has(err):

View 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())
}
}