Skip to content

Commit

Permalink
chore: use errors.New to replace fmt.Errorf with no parameters (#160)
Browse files Browse the repository at this point in the history
Signed-off-by: ChengenH <[email protected]>
  • Loading branch information
ChengenH authored Dec 10, 2024
1 parent 77a565b commit 20772f8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions internal/transaction_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func NewTransactionHandler(fn interface{}, contextHandlerType reflect.Type, hand
str, _ := handlesType.String()
return nil, fmt.Errorf("%s transactions may not take any params other than the transaction context", str)
} else if handlesType == TransactionHandlerTypeAfter && len(cf.params.fields) > 1 {
return nil, fmt.Errorf("after transactions must take at most one non-context param")
return nil, errors.New("after transactions must take at most one non-context param")
} else if handlesType == TransactionHandlerTypeAfter && len(cf.params.fields) == 1 && cf.params.fields[0].Kind() != reflect.Interface {
return nil, fmt.Errorf("after transaction must take type interface{} as their only non-context param")
return nil, errors.New("after transaction must take type interface{} as their only non-context param")
}

th := TransactionHandler{
Expand Down
5 changes: 3 additions & 2 deletions internal/types_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package internal

import (
"errors"
"fmt"
"reflect"
"sort"
Expand All @@ -30,7 +31,7 @@ func listBasicTypes() string {

func arrayOfValidType(array reflect.Value, additionalTypes []reflect.Type) error {
if array.Len() < 1 {
return fmt.Errorf("arrays must have length greater than 0")
return errors.New("arrays must have length greater than 0")
}

return typeIsValid(array.Index(0).Type(), additionalTypes, false)
Expand Down Expand Up @@ -109,7 +110,7 @@ func typeIsValid(t reflect.Type, additionalTypes []reflect.Type, allowError bool

func typeMatchesInterface(toMatch reflect.Type, iface reflect.Type) error {
if iface.Kind() != reflect.Interface {
return fmt.Errorf("type passed for interface is not an interface")
return errors.New("type passed for interface is not an interface")
}

for i := 0; i < iface.NumMethod(); i++ {
Expand Down
3 changes: 2 additions & 1 deletion metadata/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package metadata

import (
"errors"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -54,7 +55,7 @@ func getSchema(field reflect.Type, components *ComponentMetadata, nested bool) (

func buildArraySchema(array reflect.Value, components *ComponentMetadata, nested bool) (*spec.Schema, error) {
if array.Len() < 1 {
return nil, fmt.Errorf("arrays must have length greater than 0")
return nil, errors.New("arrays must have length greater than 0")
}

lowerSchema, err := getSchema(array.Index(0).Type(), components, nested)
Expand Down

0 comments on commit 20772f8

Please sign in to comment.