mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-19 20:32:35 +02:00
fix: nil when printing error in edge cases
This commit is contained in:
parent
a1f2a84a16
commit
1e24765b17
4 changed files with 13 additions and 5 deletions
|
@ -36,8 +36,11 @@ func (err *baseError) Subjectf(format string, args ...any) Error {
|
||||||
return err.Subject(format)
|
return err.Subject(format)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err baseError) With(extra error) Error {
|
func (err *baseError) With(extra error) Error {
|
||||||
return &nestedError{&err, []error{extra}}
|
if extra == nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return &nestedError{&baseError{err.Err}, []error{extra}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err baseError) Withf(format string, args ...any) Error {
|
func (err baseError) Withf(format string, args ...any) Error {
|
||||||
|
|
|
@ -31,7 +31,7 @@ func (h *Hint) String() string {
|
||||||
return h.Error()
|
return h.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
func DoYouMean(s string) *Hint {
|
func DoYouMean(s string) error {
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,8 +78,10 @@ func (err *nestedError) fmtError(appendLine appendLineFunc) []byte {
|
||||||
}
|
}
|
||||||
if err.Err != nil {
|
if err.Err != nil {
|
||||||
buf := appendLine(nil, err.Err, 0)
|
buf := appendLine(nil, err.Err, 0)
|
||||||
buf = append(buf, '\n')
|
if len(err.Extras) > 0 {
|
||||||
buf = appendLines(buf, err.Extras, 1, appendLine)
|
buf = append(buf, '\n')
|
||||||
|
buf = appendLines(buf, err.Extras, 1, appendLine)
|
||||||
|
}
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
return appendLines(nil, err.Extras, 0, appendLine)
|
return appendLines(nil, err.Extras, 0, appendLine)
|
||||||
|
|
|
@ -87,6 +87,9 @@ func Join(errors ...error) Error {
|
||||||
func JoinLines(main error, errors ...string) Error {
|
func JoinLines(main error, errors ...string) Error {
|
||||||
errs := make([]error, len(errors))
|
errs := make([]error, len(errors))
|
||||||
for i, err := range errors {
|
for i, err := range errors {
|
||||||
|
if err == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
errs[i] = newError(err)
|
errs[i] = newError(err)
|
||||||
}
|
}
|
||||||
return &nestedError{Err: main, Extras: errs}
|
return &nestedError{Err: main, Extras: errs}
|
||||||
|
|
Loading…
Add table
Reference in a new issue