Skip to content

Commit

Permalink
all: fix errs.New(fmt.Sprintf(...)) issues
Browse files Browse the repository at this point in the history
Change-Id: If92dfd34161b9eb6790177038d1d88b08042dd81
  • Loading branch information
egonelbre committed May 7, 2024
1 parent 3ef1143 commit e018de0
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions cmd/uplink/cmd_cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ func (c *cmdCp) calculatePartSize(contentLength, preferredPartSize int64, parall
// check whether we can use preferred part size instead?
if preferredPartSize > 0 {
if preferredPartSize < partSize {
return cfg, errs.New(fmt.Sprintf("the specified chunk size %s is too small, requires %s or larger",
memory.FormatBytes(preferredPartSize), memory.FormatBytes(partSize)))
return cfg, errs.New("the specified chunk size %s is too small, requires %s or larger",
memory.FormatBytes(preferredPartSize), memory.FormatBytes(partSize))
}

partSize = roundUpToNext(preferredPartSize, alignPartSize.Int64())
Expand Down
2 changes: 1 addition & 1 deletion private/mud/mud.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func Execute[A any](ctx context.Context, ball *Ball, factory interface{}) (A, er
}
}
if response[0].Interface() == nil {
return a, errs.New("Provider factory is executed without error, but returner with nil instance. " + name[A]())
return a, errs.New("Provider factory is executed without error, but returner with nil instance. %s", name[A]())
}

return response[0].Interface().(A), nil
Expand Down
8 changes: 4 additions & 4 deletions satellite/console/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1782,14 +1782,14 @@ func (s *Service) getValidatedFullName(requestData *SetUpAccountRequest) (name s
}

if len(*requestData.FirstName) == 0 || len(*requestData.FirstName) > s.config.MaxNameCharacters {
return "", errs.New(fmt.Sprintf("First name length must be more then 0 and less then or equal to %d", s.config.MaxNameCharacters))
return "", errs.New("First name length must be more then 0 and less then or equal to %d", s.config.MaxNameCharacters)
}

name = *requestData.FirstName

if requestData.LastName != nil {
if len(*requestData.LastName) > s.config.MaxNameCharacters {
return "", errs.New(fmt.Sprintf("Last name length must be less then or equal to %d", s.config.MaxNameCharacters))
return "", errs.New("Last name length must be less then or equal to %d", s.config.MaxNameCharacters)
}

name += " " + *requestData.LastName
Expand All @@ -1800,7 +1800,7 @@ func (s *Service) getValidatedFullName(requestData *SetUpAccountRequest) (name s
}

if len(*requestData.FullName) == 0 || len(*requestData.FullName) > s.config.MaxNameCharacters {
return "", errs.New(fmt.Sprintf("Full name length must be more then 0 and less then or equal to %d", s.config.MaxNameCharacters))
return "", errs.New("Full name length must be more then 0 and less then or equal to %d", s.config.MaxNameCharacters)
}

name = *requestData.FullName
Expand All @@ -1816,7 +1816,7 @@ func (s *Service) getValidatedCompanyName(requestData *SetUpAccountRequest) (nam
}

if len(*requestData.CompanyName) == 0 || len(*requestData.CompanyName) > s.config.MaxNameCharacters {
return nil, errs.New(fmt.Sprintf("Company name length must be more then 0 and less then or equal to %d", s.config.MaxNameCharacters))
return nil, errs.New("Company name length must be more then 0 and less then or equal to %d", s.config.MaxNameCharacters)
}

name = requestData.CompanyName
Expand Down
4 changes: 2 additions & 2 deletions satellite/emission/dimen.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type Val struct {
// Add sums two Val instances with the same dimensions.
func (a Val) Add(b Val) (Val, error) {
if a.Unit != b.Unit {
return Val{}, errs.New(fmt.Sprintf("cannot add units %s, %s", a.Unit.String(), b.Unit.String()))
return Val{}, errs.New("cannot add units %v, %v", a.Unit, b.Unit)
}
r := a
r.Value += b.Value
Expand All @@ -110,7 +110,7 @@ func (a Val) Add(b Val) (Val, error) {
// Sub subtracts one Val from another if they have the same dimensions.
func (a Val) Sub(b Val) (Val, error) {
if a.Unit != b.Unit {
return Val{}, errs.New(fmt.Sprintf("cannot subtract units %s, %s", a.Unit.String(), b.Unit.String()))
return Val{}, errs.New("cannot subtract units %v, %v", a.Unit, b.Unit)
}
r := a
r.Value -= b.Value
Expand Down
2 changes: 1 addition & 1 deletion satellite/metabase/mud.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewSpannerTestDatabase(ctx context.Context, logger *zap.Logger, spannerConn

matches := regexp.MustCompile("^(.*)/databases/(.*)$").FindStringSubmatch(databaseName)
if matches == nil || len(matches) != 3 {
return SpannerTestDatabase{}, errs.New("database connection should be defined in the form of 'projects/<PROJECT>/instances/<INSTANCE>/databases/<DATABASE>', but it was " + spannerConnection)
return SpannerTestDatabase{}, errs.New("database connection should be defined in the form of 'projects/<PROJECT>/instances/<INSTANCE>/databases/<DATABASE>', but it was %q", spannerConnection)
}

req := &databasepb.CreateDatabaseRequest{
Expand Down
8 changes: 4 additions & 4 deletions satellite/payments/stripe/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (accounts *accounts) SaveBillingAddress(ctx context.Context, userID uuid.UU
if err != nil {
stripeErr := &stripe.Error{}
if errors.As(err, &stripeErr) {
err = errs.New(stripeErr.Msg)
err = errs.Wrap(errors.New(stripeErr.Msg))
}
return nil, Error.Wrap(err)
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func (accounts *accounts) AddTaxID(ctx context.Context, userID uuid.UUID, taxID
if stripeErr.Code == stripe.ErrorCodeTaxIDInvalid {
err = Error.Wrap(ErrInvalidTaxID.New("Tax validation error: %s", stripeErr.Msg))
} else {
err = errs.New(stripeErr.Msg)
err = errs.Wrap(errors.New(stripeErr.Msg))
}
}
return nil, Error.Wrap(err)
Expand Down Expand Up @@ -201,7 +201,7 @@ func (accounts *accounts) RemoveTaxID(ctx context.Context, userID uuid.UUID, id
if err != nil {
stripeErr := &stripe.Error{}
if errors.As(err, &stripeErr) {
err = errs.New(stripeErr.Msg)
err = errs.Wrap(errors.New(stripeErr.Msg))
}
return nil, Error.Wrap(err)
}
Expand Down Expand Up @@ -234,7 +234,7 @@ func (accounts *accounts) GetBillingInformation(ctx context.Context, userID uuid
if err != nil {
stripeErr := &stripe.Error{}
if errors.As(err, &stripeErr) {
err = errs.New(stripeErr.Msg)
err = errs.Wrap(errors.New(stripeErr.Msg))
}
return nil, Error.Wrap(err)
}
Expand Down
4 changes: 2 additions & 2 deletions satellite/payments/stripe/creditcards.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (creditCards *creditCards) Add(ctx context.Context, userID uuid.UUID, cardT
if err != nil {
stripeErr := &stripe.Error{}
if errors.As(err, &stripeErr) {
err = errs.New(stripeErr.Msg)
err = errs.Wrap(errors.New(stripeErr.Msg))
}
return payments.CreditCard{}, Error.Wrap(err)
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func (creditCards *creditCards) AddByPaymentMethodID(ctx context.Context, userID
if err != nil {
stripeErr := &stripe.Error{}
if errors.As(err, &stripeErr) {
err = errs.New(stripeErr.Msg)
err = errs.Wrap(errors.New(stripeErr.Msg))
}
return payments.CreditCard{}, Error.Wrap(err)
}
Expand Down

0 comments on commit e018de0

Please sign in to comment.