jldb/lib/errs/fmt.go

23 lines
405 B
Go
Raw Normal View History

2023-10-13 09:43:27 +00:00
package errs
import "fmt"
func FmtDetails(err error) string {
e, ok := err.(*Error)
if !ok {
return err.Error()
}
var s string
if e.collection != "" || e.index != "" {
2023-12-05 10:24:03 +00:00
s = fmt.Sprintf(`[%d] (%s/%s) %s`, e.Code, e.collection, e.index, e.Msg)
2023-10-13 09:43:27 +00:00
} else {
2023-12-05 10:24:03 +00:00
s = fmt.Sprintf("[%d] %s", e.Code, e.Msg)
2023-10-13 09:43:27 +00:00
}
2023-12-05 10:24:03 +00:00
if len(e.StackTrace) != 0 {
s += "\n\nStack Trace:\n" + e.StackTrace + "\n"
2023-10-13 09:43:27 +00:00
}
return s
}