From 88642770c54f8db2ad170a7551d9241d1ce3c047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Tue, 14 Nov 2023 16:00:14 +0100 Subject: [PATCH] v0.0.321 Add .NoLog() to lowest-level query exerr.Wrap in wmo (otherwise we get error logs on stdout even if the callign method allows mongo.ErrNoDocuments) --- exerr/builder.go | 14 ++++++++++++-- goextVersion.go | 4 ++-- wmo/decoding.go | 8 ++++---- wmo/queryFindOne.go | 8 ++++---- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/exerr/builder.go b/exerr/builder.go index 2d60127..264d382 100644 --- a/exerr/builder.go +++ b/exerr/builder.go @@ -70,6 +70,7 @@ func init() { type Builder struct { errorData *ExErr containsGinData bool + noLog bool } func Get(err error) *Builder { @@ -190,6 +191,13 @@ func (b *Builder) System() *Builder { // ---------------------------------------------------------------------------- +func (b *Builder) NoLog() *Builder { + b.noLog = true + return b +} + +// ---------------------------------------------------------------------------- + func (b *Builder) Id(key string, val fmt.Stringer) *Builder { return b.addMeta(key, MDTID, newIDWrap(val)) } @@ -401,12 +409,14 @@ func extractHeader(header map[string][]string) []string { // Build creates a new error, ready to pass up the stack // If the errors is not SevWarn or SevInfo it gets also logged (in short form, without stacktrace) onto stdout +// Can be gloablly configured with ZeroLogErrTraces and ZeroLogAllTraces +// Can be locally suppressed with Builder.NoLog() func (b *Builder) Build() error { warnOnPkgConfigNotInitialized() - if pkgconfig.ZeroLogErrTraces && (b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal) { + if pkgconfig.ZeroLogErrTraces && !b.noLog && (b.errorData.Severity == SevErr || b.errorData.Severity == SevFatal) { b.errorData.ShortLog(stackSkipLogger.Error()) - } else if pkgconfig.ZeroLogAllTraces { + } else if pkgconfig.ZeroLogAllTraces && !b.noLog { b.errorData.ShortLog(stackSkipLogger.Error()) } diff --git a/goextVersion.go b/goextVersion.go index 10359c3..33cdfc9 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.320" +const GoextVersion = "0.0.321" -const GoextVersionTimestamp = "2023-11-14T14:50:27+0100" +const GoextVersionTimestamp = "2023-11-14T16:00:14+0100" diff --git a/wmo/decoding.go b/wmo/decoding.go index 9b7e4bc..a60d107 100644 --- a/wmo/decoding.go +++ b/wmo/decoding.go @@ -14,12 +14,12 @@ func (c *Coll[TData]) decodeSingle(ctx context.Context, dec Decodable) (TData, e if c.customDecoder != nil { res, err = (*c.customDecoder)(ctx, dec) if err != nil { - return *new(TData), exerr.Wrap(err, "failed to decode single entity with custom-decoder").Type("decoder", *c.customDecoder).Build() + return *new(TData), exerr.Wrap(err, "failed to decode single entity with custom-decoder").Type("decoder", *c.customDecoder).NoLog().Build() } } else { err = dec.Decode(&res) if err != nil { - return *new(TData), exerr.Wrap(err, "failed to decode single entity").Type("target-type", res).Build() + return *new(TData), exerr.Wrap(err, "failed to decode single entity").Type("target-type", res).NoLog().Build() } } @@ -75,12 +75,12 @@ func (c *Coll[TData]) decodeSingleOrRequery(ctx context.Context, dec Decodable) var res genDoc err := dec.Decode(&res) if err != nil { - return *new(TData), exerr.Wrap(err, "failed to ID-decode entity").Build() + return *new(TData), exerr.Wrap(err, "failed to ID-decode entity").NoLog().Build() } v, err := c.findOneInternal(ctx, bson.M{"_id": res.ID}, false) if err != nil { - return *new(TData), exerr.Wrap(err, "failed to re-query entity").Any("_id", res.ID).Build() + return *new(TData), exerr.Wrap(err, "failed to re-query entity").Any("_id", res.ID).NoLog().Build() } return *v, nil diff --git a/wmo/queryFindOne.go b/wmo/queryFindOne.go index acd43a1..be5d7ec 100644 --- a/wmo/queryFindOne.go +++ b/wmo/queryFindOne.go @@ -58,7 +58,7 @@ func (c *Coll[TData]) findOneInternal(ctx context.Context, filter bson.M, allowN return nil, nil } if err != nil { - return nil, exerr.Wrap(err, "mongo-query[find-one] failed").Any("filter", filter).Str("collection", c.Name()).Build() + return nil, exerr.Wrap(err, "mongo-query[find-one] failed").Any("filter", filter).Str("collection", c.Name()).NoLog().Build() } return &res, nil @@ -75,19 +75,19 @@ func (c *Coll[TData]) findOneInternal(ctx context.Context, filter bson.M, allowN cursor, err := c.coll.Aggregate(ctx, pipeline) if err != nil { - return nil, exerr.Wrap(err, "mongo-aggregation [find-one] failed").Any("pipeline", pipeline).Str("collection", c.Name()).Build() + return nil, exerr.Wrap(err, "mongo-aggregation [find-one] failed").Any("pipeline", pipeline).Str("collection", c.Name()).NoLog().Build() } if cursor.Next(ctx) { v, err := c.decodeSingle(ctx, cursor) if err != nil { - return nil, exerr.Wrap(err, "mongo-aggregation [find-one] failed to decode results").Any("pipeline", pipeline).Str("collection", c.Name()).Build() + return nil, exerr.Wrap(err, "mongo-aggregation [find-one] failed to decode results").Any("pipeline", pipeline).Str("collection", c.Name()).NoLog().Build() } return &v, nil } else if allowNull { return nil, nil } else { - return nil, exerr.Wrap(mongo.ErrNoDocuments, "mongo-aggregation [find-one] returned no documents").Any("pipeline", pipeline).Str("collection", c.Name()).Build() + return nil, exerr.Wrap(mongo.ErrNoDocuments, "mongo-aggregation [find-one] returned no documents").Any("pipeline", pipeline).Str("collection", c.Name()).NoLog().Build() } } }