mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-26 11:01:07 +01:00
fixed error subject missing in some cases
This commit is contained in:
@@ -182,8 +182,7 @@ func (ne NestedError) Subjectf(format string, args ...any) NestedError {
|
||||
if strings.Contains(format, "%w") {
|
||||
panic("Subjectf format should not contain %w")
|
||||
}
|
||||
ne.subject = fmt.Sprintf(format, args...)
|
||||
return ne
|
||||
return ne.Subject(fmt.Sprintf(format, args...))
|
||||
}
|
||||
|
||||
func (ne NestedError) JSONObject() jsonNestedError {
|
||||
|
||||
@@ -2,6 +2,7 @@ package error
|
||||
|
||||
import (
|
||||
stderrors "errors"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -13,6 +14,7 @@ var (
|
||||
ErrMissing = stderrors.New("missing")
|
||||
ErrDuplicated = stderrors.New("duplicated")
|
||||
ErrOutOfRange = stderrors.New("out of range")
|
||||
ErrTypeError = stderrors.New("type error")
|
||||
)
|
||||
|
||||
const fmtSubjectWhat = "%w %v: %q"
|
||||
@@ -57,6 +59,10 @@ func Duplicated(subject, what any) NestedError {
|
||||
return errorf("%w %v: %v", ErrDuplicated, subject, what)
|
||||
}
|
||||
|
||||
func OutOfRange(subject string, value any) NestedError {
|
||||
func OutOfRange(subject any, value any) NestedError {
|
||||
return errorf("%v %w: %v", subject, ErrOutOfRange, value)
|
||||
}
|
||||
|
||||
func TypeError(subject any, from, to reflect.Value) NestedError {
|
||||
return errorf("%v %w: %T -> %T", subject, ErrTypeError, from.Interface(), to.Interface())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user