Skip to content

Commit

Permalink
fix errors tinyint
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-li committed Oct 10, 2024
1 parent 5d31f69 commit abbfdf5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions marshal/tinyint/marshal_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func EncString(v string) ([]byte, error) {

n, err := strconv.ParseInt(v, 10, 8)
if err != nil {
return nil, fmt.Errorf("failed to marshal tinyint: can not marshal %#v %s", v, err)
return nil, fmt.Errorf("failed to marshal tinyint: can not marshal (%T)(%[1]v) %s", v, err)
}
return []byte{byte(n)}, nil
}
Expand All @@ -187,15 +187,15 @@ func EncReflect(v reflect.Value) ([]byte, error) {
case reflect.Int, reflect.Int64, reflect.Int32, reflect.Int16:
val := v.Int()
if val > math.MaxInt8 || val < math.MinInt8 {
return nil, fmt.Errorf("failed to marshal tinyint: value %#v out of range", v.Interface())
return nil, fmt.Errorf("failed to marshal tinyint: value (%T)(%[1]v) out of range", v.Interface())
}
return []byte{byte(val)}, nil
case reflect.Uint8:
return []byte{byte(v.Uint())}, nil
case reflect.Uint, reflect.Uint64, reflect.Uint32, reflect.Uint16:
val := v.Uint()
if val > math.MaxUint8 {
return nil, fmt.Errorf("failed to marshal tinyint: value %#v out of range", v.Interface())
return nil, fmt.Errorf("failed to marshal tinyint: value (%T)(%[1]v) out of range", v.Interface())
}
return []byte{byte(val)}, nil
case reflect.String:
Expand All @@ -206,11 +206,11 @@ func EncReflect(v reflect.Value) ([]byte, error) {

n, err := strconv.ParseInt(val, 10, 8)
if err != nil {
return nil, fmt.Errorf("failed to marshal tinyint: can not marshal %#v %s", v.Interface(), err)
return nil, fmt.Errorf("failed to marshal tinyint: can not marshal (%T)(%[1]v) %s", v.Interface(), err)
}
return []byte{byte(n)}, nil
default:
return nil, fmt.Errorf("failed to marshal tinyint: unsupported value type (%T)(%#[1]v)", v.Interface())
return nil, fmt.Errorf("failed to marshal tinyint: unsupported value type (%T)(%[1]v)", v.Interface())
}
}

Expand Down
2 changes: 1 addition & 1 deletion marshal/tinyint/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Unmarshal(data []byte, value interface{}) error {
rv := reflect.ValueOf(value)
rt := rv.Type()
if rt.Kind() != reflect.Ptr {
return fmt.Errorf("failed to unmarshal tinyint: unsupported value type %#v", value)
return fmt.Errorf("failed to unmarshal tinyint: unsupported value type (%T)(%[1]v)", v)
}
if rt.Elem().Kind() != reflect.Ptr {
return DecReflect(data, rv)
Expand Down
6 changes: 3 additions & 3 deletions marshal/tinyint/unmarshal_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var errWrongDataLen = fmt.Errorf("failed to unmarshal tinyint: the length of the data should less or equal then 1")

func errNilReference(v interface{}) error {
return fmt.Errorf("failed to unmarshal tinyint: can not unmarshal into nil reference %#v)", v)
return fmt.Errorf("failed to unmarshal tinyint: can not unmarshal into nil reference(%T)(%[1]v)", v)
}

func DecInt8(p []byte, v *int8) error {
Expand Down Expand Up @@ -451,7 +451,7 @@ func DecReflect(p []byte, v reflect.Value) error {
case reflect.String:
return decReflectString(p, v)
default:
return fmt.Errorf("failed to unmarshal tinyint: unsupported value type %#v)", v.Interface())
return fmt.Errorf("failed to unmarshal tinyint: unsupported value type (%T)(%[1]v)", v.Interface())
}
}

Expand All @@ -468,7 +468,7 @@ func DecReflectR(p []byte, v reflect.Value) error {
case reflect.String:
return decReflectStringR(p, v)
default:
return fmt.Errorf("failed to unmarshal tinyint: unsupported value type (%T)(%#[1]v)", v.Interface())
return fmt.Errorf("failed to unmarshal tinyint: unsupported value type (%T)(%[1]v)", v.Interface())
}
}

Expand Down

0 comments on commit abbfdf5

Please sign in to comment.