simplified error messages

This commit is contained in:
yusing
2024-10-19 14:25:28 +08:00
parent bd732dfa0a
commit 01ffe0d97c
7 changed files with 43 additions and 19 deletions

View File

@@ -133,7 +133,11 @@ func (ne NestedError) With(s any) NestedError {
switch ss := s.(type) {
case nil:
return ne
case NestedError:
case *NestedErrorImpl:
if len(ss.extras) == 1 {
ne.extras = append(ne.extras, ss.extras[0])
return ne
}
return ne.withError(ss)
case error:
return ne.withError(From(ss))
@@ -248,10 +252,11 @@ func (ne NestedError) writeToSB(sb *strings.Builder, level int, prefix string) {
return
}
sb.WriteString(ne.err.Error())
if ne.subject != "" {
sb.WriteString(fmt.Sprintf(" for %q", ne.subject))
sb.WriteString(ne.subject)
sb.WriteRune(' ')
}
sb.WriteString(ne.err.Error())
if len(ne.extras) > 0 {
sb.WriteRune(':')
for _, extra := range ne.extras {