Compare commits

...

2 Commits

Author SHA1 Message Date
2f1b784dc2 v0.0.219 implement error.Is(*) for exerr 2023-07-28 15:42:12 +02:00
190584e0e6 v0.0.218 bf 2023-07-27 17:16:30 +02:00
4 changed files with 15 additions and 7 deletions

View File

@@ -22,7 +22,7 @@ type ExErr struct {
WrappedErrType string `json:"wrappedErrType"` WrappedErrType string `json:"wrappedErrType"`
Caller string `json:"caller"` Caller string `json:"caller"`
OriginalError *ExErr OriginalError *ExErr `json:"originalError"`
Meta MetaMap `json:"meta"` Meta MetaMap `json:"meta"`
} }
@@ -31,10 +31,16 @@ func (ee *ExErr) Error() string {
return ee.Message return ee.Message
} }
// Unwrap must be implemented so that some error.XXX methods work
func (ee *ExErr) Unwrap() error { func (ee *ExErr) Unwrap() error {
return ee.OriginalError return ee.OriginalError
} }
// Is must be implemented so that error.Is(x) works
func (ee *ExErr) Is(e error) bool {
return IsFrom(ee, e)
}
func (ee *ExErr) Log(evt *zerolog.Event) { func (ee *ExErr) Log(evt *zerolog.Event) {
evt.Msg(ee.FormatLog(LogPrintFull)) evt.Msg(ee.FormatLog(LogPrintFull))
} }

View File

@@ -24,6 +24,8 @@ func IsFrom(e error, original error) bool {
if e == nil { if e == nil {
return false return false
} }
//goland:noinspection GoDirectComparisonOfErrors
if e == original { if e == original {
return true return true
} }

View File

@@ -1,5 +1,5 @@
package goext package goext
const GoextVersion = "0.0.217" const GoextVersion = "0.0.219"
const GoextVersionTimestamp = "2023-07-27T17:12:41+0200" const GoextVersionTimestamp = "2023-07-28T15:42:12+0200"

View File

@@ -54,7 +54,7 @@ func (tx *transaction) Rollback() error {
result := tx.tx.Rollback() result := tx.tx.Rollback()
if result != nil { if result == nil {
tx.status = TxStatusRollback tx.status = TxStatusRollback
} }
@@ -75,7 +75,7 @@ func (tx *transaction) Commit() error {
result := tx.tx.Commit() result := tx.tx.Commit()
if result != nil { if result == nil {
tx.status = TxStatusComitted tx.status = TxStatusComitted
} }
@@ -97,7 +97,7 @@ func (tx *transaction) Exec(ctx context.Context, sqlstr string, prep PP) (sql.Re
res, err := tx.tx.NamedExecContext(ctx, sqlstr, prep) res, err := tx.tx.NamedExecContext(ctx, sqlstr, prep)
if tx.status == TxStatusInitial && err != nil { if tx.status == TxStatusInitial && err == nil {
tx.status = TxStatusActive tx.status = TxStatusActive
} }
@@ -122,7 +122,7 @@ func (tx *transaction) Query(ctx context.Context, sqlstr string, prep PP) (*sqlx
rows, err := sqlx.NamedQueryContext(ctx, tx.tx, sqlstr, prep) rows, err := sqlx.NamedQueryContext(ctx, tx.tx, sqlstr, prep)
if tx.status == TxStatusInitial && err != nil { if tx.status == TxStatusInitial && err == nil {
tx.status = TxStatusActive tx.status = TxStatusActive
} }