mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-19 15:01:22 +02:00
fix deserialization panics on empty map
This commit is contained in:
@@ -18,11 +18,11 @@ func TestBaseWithSubject(t *testing.T) {
|
||||
withSubjectf := err.Subjectf("%s %s", "foo", "bar")
|
||||
|
||||
ExpectError(t, err, withSubject)
|
||||
ExpectStrEqual(t, withSubject.Error(), "foo: error")
|
||||
ExpectEqual(t, withSubject.Error(), "foo: error")
|
||||
ExpectTrue(t, withSubject.Is(err))
|
||||
|
||||
ExpectError(t, err, withSubjectf)
|
||||
ExpectStrEqual(t, withSubjectf.Error(), "foo bar: error")
|
||||
ExpectEqual(t, withSubjectf.Error(), "foo bar: error")
|
||||
ExpectTrue(t, withSubjectf.Is(err))
|
||||
}
|
||||
|
||||
@@ -114,9 +114,9 @@ func TestErrorWith(t *testing.T) {
|
||||
func TestErrorStringSimple(t *testing.T) {
|
||||
errFailure := New("generic failure")
|
||||
ne := errFailure.Subject("foo bar")
|
||||
ExpectStrEqual(t, ne.Error(), "foo bar: generic failure")
|
||||
ExpectEqual(t, ne.Error(), "foo bar: generic failure")
|
||||
ne = ne.Subject("baz")
|
||||
ExpectStrEqual(t, ne.Error(), "baz > foo bar: generic failure")
|
||||
ExpectEqual(t, ne.Error(), "baz > foo bar: generic failure")
|
||||
}
|
||||
|
||||
func TestErrorStringNested(t *testing.T) {
|
||||
@@ -153,5 +153,5 @@ func TestErrorStringNested(t *testing.T) {
|
||||
• action 3 > inner3: generic failure
|
||||
• 3
|
||||
• 3`
|
||||
ExpectStrEqual(t, ne.Error(), want)
|
||||
ExpectEqual(t, ne.Error(), want)
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user