v0.0.370 improve sq errors
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m36s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m36s
This commit is contained in:
@@ -68,6 +68,7 @@ func init() {
|
||||
}
|
||||
|
||||
type Builder struct {
|
||||
wrappedErr error
|
||||
errorData *ExErr
|
||||
containsGinData bool
|
||||
noLog bool
|
||||
@@ -89,9 +90,9 @@ func Wrap(err error, msg string) *Builder {
|
||||
if !pkgconfig.RecursiveErrors {
|
||||
v := FromError(err)
|
||||
v.Message = msg
|
||||
return &Builder{errorData: v}
|
||||
return &Builder{wrappedErr: err, errorData: v}
|
||||
}
|
||||
return &Builder{errorData: wrapExErr(FromError(err), msg, CatWrap, 1)}
|
||||
return &Builder{wrappedErr: err, errorData: wrapExErr(FromError(err), msg, CatWrap, 1)}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -414,6 +415,10 @@ func extractHeader(header map[string][]string) []string {
|
||||
func (b *Builder) Build() error {
|
||||
warnOnPkgConfigNotInitialized()
|
||||
|
||||
if pkgconfig.DisableErrorWrapping && b.wrappedErr != nil {
|
||||
return b.wrappedErr
|
||||
}
|
||||
|
||||
if pkgconfig.ZeroLogErrTraces && !b.noLog && (b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal) {
|
||||
b.errorData.ShortLog(stackSkipLogger.Error())
|
||||
} else if pkgconfig.ZeroLogAllTraces && !b.noLog {
|
||||
|
@@ -13,6 +13,7 @@ type ErrorPackageConfig struct {
|
||||
IncludeMetaInGinOutput bool // Log meta fields ( from e.g. `.Str(key, val).Build()` ) to gin in err.Output()
|
||||
ExtendGinOutput func(err *ExErr, json map[string]any) // (Optionally) extend the gin output with more fields
|
||||
ExtendGinDataOutput func(err *ExErr, depth int, json map[string]any) // (Optionally) extend the gin `__data` output with more fields
|
||||
DisableErrorWrapping bool // Disables the exerr.Wrap()...Build() function - will always return the original error
|
||||
}
|
||||
|
||||
type ErrorPackageConfigInit struct {
|
||||
@@ -23,6 +24,7 @@ type ErrorPackageConfigInit struct {
|
||||
IncludeMetaInGinOutput *bool
|
||||
ExtendGinOutput func(err *ExErr, json map[string]any)
|
||||
ExtendGinDataOutput func(err *ExErr, depth int, json map[string]any)
|
||||
DisableErrorWrapping *bool
|
||||
}
|
||||
|
||||
var initialized = false
|
||||
@@ -35,6 +37,7 @@ var pkgconfig = ErrorPackageConfig{
|
||||
IncludeMetaInGinOutput: true,
|
||||
ExtendGinOutput: func(err *ExErr, json map[string]any) {},
|
||||
ExtendGinDataOutput: func(err *ExErr, depth int, json map[string]any) {},
|
||||
DisableErrorWrapping: false,
|
||||
}
|
||||
|
||||
// Init initializes the exerr packages
|
||||
@@ -63,6 +66,7 @@ func Init(cfg ErrorPackageConfigInit) {
|
||||
IncludeMetaInGinOutput: langext.Coalesce(cfg.IncludeMetaInGinOutput, pkgconfig.IncludeMetaInGinOutput),
|
||||
ExtendGinOutput: ego,
|
||||
ExtendGinDataOutput: egdo,
|
||||
DisableErrorWrapping: langext.Coalesce(cfg.DisableErrorWrapping, pkgconfig.DisableErrorWrapping),
|
||||
}
|
||||
|
||||
initialized = true
|
||||
|
Reference in New Issue
Block a user