From 3b918fb0409cd46e43824b73f33de659862b291f Mon Sep 17 00:00:00 2001 From: Skyxim Date: Sun, 15 Dec 2024 10:04:46 +0800 Subject: [PATCH] fix: handle invalid values in Decoder's decode method --- common/structure/structure.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/structure/structure.go b/common/structure/structure.go index 99c980bc4c..9c8034cb4f 100644 --- a/common/structure/structure.go +++ b/common/structure/structure.go @@ -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() {