Skip to content

Commit

Permalink
fix: handle invalid values in Decoder's decode method
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyxim committed Dec 15, 2024
1 parent c786b72 commit 3b918fb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions common/structure/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func (d *Decoder) Decode(src map[string]any, dst any) error {
}

func (d *Decoder) decode(name string, data any, val reflect.Value) error {
if !val.IsValid() {
// TODO: Why is an invalid value generated?
// If an invalid value is passed to `decodeString`, it will panic due to the call to `Type()`.
return fmt.Errorf("'%s' is not valid", name)
}
for {
kind := val.Kind()
if kind == reflect.Pointer && val.IsNil() {
Expand Down

0 comments on commit 3b918fb

Please sign in to comment.