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:
parent
aae8a706e9
commit
be24f7a190
@ -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
|
||||
|
@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.369"
|
||||
const GoextVersion = "0.0.370"
|
||||
|
||||
const GoextVersionTimestamp = "2024-01-13T02:01:30+0100"
|
||||
const GoextVersionTimestamp = "2024-01-13T14:10:25+0100"
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/exerr"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"sync"
|
||||
)
|
||||
@ -56,7 +57,7 @@ func (db *database) Exec(ctx context.Context, sqlstr string, prep PP) (sql.Resul
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, exerr.Wrap(err, "Failed to [exec] sql statement").Str("original_sql", origsql).Str("sql", sqlstr).Any("sql_params", prep).Build()
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
@ -77,7 +78,7 @@ func (db *database) Query(ctx context.Context, sqlstr string, prep PP) (*sqlx.Ro
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, exerr.Wrap(err, "Failed to [query] sql statement").Str("original_sql", origsql).Str("sql", sqlstr).Any("sql_params", prep).Build()
|
||||
}
|
||||
return rows, nil
|
||||
}
|
||||
@ -97,7 +98,7 @@ func (db *database) Ping(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return exerr.Wrap(err, "Failed to [ping] sql database").Build()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -117,7 +118,7 @@ func (db *database) BeginTransaction(ctx context.Context, iso sql.IsolationLevel
|
||||
|
||||
xtx, err := db.db.BeginTxx(ctx, &sql.TxOptions{Isolation: iso})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, exerr.Wrap(err, "Failed to start sql transaction").Build()
|
||||
}
|
||||
|
||||
for _, v := range db.lstr {
|
||||
|
Loading…
Reference in New Issue
Block a user