Skip to content

Commit

Permalink
add error on nil reference values counter
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-li committed Oct 10, 2024
1 parent 2bb2f93 commit 5d31f69
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 19 deletions.
4 changes: 2 additions & 2 deletions marshal/counter/marshal_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ func EncReflect(v reflect.Value) ([]byte, error) {
}
n, err := strconv.ParseInt(val, 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to marshal counter: can not marshal %#v %s", v.Interface(), err)
return nil, fmt.Errorf("failed to marshal counter: can not marshal (%T)(%[1]v) %s", v.Interface(), err)
}
return encInt64(n), nil
default:
return nil, fmt.Errorf("failed to marshal counter: unsupported value type (%T)(%#[1]v)", v.Interface())
return nil, fmt.Errorf("failed to marshal counter: unsupported value type (%T)(%[1]v)", v.Interface())
}
}

Expand Down
2 changes: 1 addition & 1 deletion marshal/counter/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 counter: unsupported value type (%T)(%#[1]v)", value)
return fmt.Errorf("failed to unmarshal counter: unsupported value type (%T)(%[1]v)", value)
}
if rt.Elem().Kind() != reflect.Ptr {
return DecReflect(data, rv)
Expand Down
Loading

0 comments on commit 5d31f69

Please sign in to comment.