fix deserialization panics on empty map

This commit is contained in:
yusing
2024-12-18 15:15:55 +08:00
parent 36069cbe6d
commit 654194b274
7 changed files with 123 additions and 28 deletions

View File

@@ -1,7 +1,6 @@
package err
import (
"errors"
"fmt"
)
@@ -20,12 +19,16 @@ func Errorf(format string, args ...any) Error {
return &baseError{fmt.Errorf(format, args...)}
}
func From(err error) (e Error) {
func From(err error) Error {
if err == nil {
return nil
}
if errors.As(err, &e) {
return e
//nolint:errorlint
switch err := err.(type) {
case *baseError:
return err
case *nestedError:
return err
}
return &baseError{err}
}