v0.0.490 documentation and extra-params in exerr
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 4m2s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 4m2s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package exerr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/xid"
|
||||
"github.com/rs/zerolog"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
@@ -26,7 +27,8 @@ type ExErr struct {
|
||||
|
||||
OriginalError *ExErr `json:"originalError"`
|
||||
|
||||
Meta MetaMap `json:"meta"`
|
||||
Extra map[string]any `json:"extra"`
|
||||
Meta MetaMap `json:"meta"`
|
||||
}
|
||||
|
||||
func (ee *ExErr) Error() string {
|
||||
@@ -81,6 +83,23 @@ func (ee *ExErr) Log(evt *zerolog.Event) {
|
||||
}
|
||||
|
||||
func (ee *ExErr) FormatLog(lvl LogPrintLevel) string {
|
||||
|
||||
// [LogPrintShort]
|
||||
//
|
||||
// - Only print message and type
|
||||
// - Used e.g. for logging to the console when Build is called
|
||||
// - also used in Print() if level == Warn/Info
|
||||
//
|
||||
// [LogPrintOverview]
|
||||
//
|
||||
// - print message, extra and errortrace
|
||||
//
|
||||
// [LogPrintFull]
|
||||
//
|
||||
// - print full error, with meta and extra, and trace, etc
|
||||
// - Used in Output() and Print()
|
||||
//
|
||||
|
||||
if lvl == LogPrintShort {
|
||||
|
||||
msg := ee.Message
|
||||
@@ -101,6 +120,10 @@ func (ee *ExErr) FormatLog(lvl LogPrintLevel) string {
|
||||
|
||||
str := "[" + ee.RecursiveType().Key + "] <" + ee.UniqueID + "> " + strings.ReplaceAll(ee.RecursiveMessage(), "\n", " ") + "\n"
|
||||
|
||||
for exk, exv := range ee.Extra {
|
||||
str += fmt.Sprintf(" # [[[ %s ==> %v ]]]\n", exk, exv)
|
||||
}
|
||||
|
||||
indent := ""
|
||||
for curr := ee; curr != nil; curr = curr.OriginalError {
|
||||
indent += " "
|
||||
@@ -122,6 +145,10 @@ func (ee *ExErr) FormatLog(lvl LogPrintLevel) string {
|
||||
|
||||
str := "[" + ee.RecursiveType().Key + "] <" + ee.UniqueID + "> " + strings.ReplaceAll(ee.RecursiveMessage(), "\n", " ") + "\n"
|
||||
|
||||
for exk, exv := range ee.Extra {
|
||||
str += fmt.Sprintf(" # [[[ %s ==> %v ]]]\n", exk, exv)
|
||||
}
|
||||
|
||||
indent := ""
|
||||
for curr := ee; curr != nil; curr = curr.OriginalError {
|
||||
indent += " "
|
||||
@@ -328,6 +355,14 @@ func (ee *ExErr) GetMetaTime(key string) (time.Time, bool) {
|
||||
return time.Time{}, false
|
||||
}
|
||||
|
||||
func (ee *ExErr) GetExtra(key string) (any, bool) {
|
||||
if v, ok := ee.Extra[key]; ok {
|
||||
return v, true
|
||||
}
|
||||
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// contains test if the supplied error is contained in this error (anywhere in the chain)
|
||||
func (ee *ExErr) contains(original *ExErr) (*ExErr, bool) {
|
||||
if original == nil {
|
||||
|
Reference in New Issue
Block a user