From dfd1aca57e47e3aeb05a06b44d053781e8b8b945 Mon Sep 17 00:00:00 2001 From: Nicolas JUHEL Date: Wed, 26 Oct 2022 14:20:44 +0200 Subject: [PATCH] Package Error : - Add function to create new Error with runtine Frame information (used for trace) - Add a private slice of error in DefaultReturn model to add them Gin Error and retrurn them into log / stdout Bump dependencies - Fix CVE-2022-32149 --- errors/errors.go | 18 +++++++++++++++++ errors/return.go | 23 +++++++++++++++++++++- go.mod | 51 ++++++++++++++++++++++++------------------------ 3 files changed, 66 insertions(+), 26 deletions(-) diff --git a/errors/errors.go b/errors/errors.go index ee5fb8d3..4e718bf5 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -201,6 +201,24 @@ func NewError(code uint16, message string, parent Error) Error { } } +func NewErrorTrace(code int, msg string, file string, line int, parent Error) Error { + var p = make([]Error, 0) + + if parent != nil { + p = parent.GetIErrorSlice() + } + + return &errors{ + c: uint16(code), + e: msg, + p: p, + t: runtime.Frame{ + File: file, + Line: line, + }, + } +} + func NewErrorIferror(code uint16, message string, parent error) Error { if parent == nil { return nil diff --git a/errors/return.go b/errors/return.go index 59120995..85b72a57 100644 --- a/errors/return.go +++ b/errors/return.go @@ -45,6 +45,7 @@ type Return interface { type DefaultReturn struct { Code string Message string + err []error } func NewDefaultReturn() *DefaultReturn { @@ -57,10 +58,20 @@ func NewDefaultReturn() *DefaultReturn { func (r *DefaultReturn) SetError(code int, msg string, file string, line int) { r.Code = fmt.Sprintf("%d", code) r.Message = msg + + if len(r.err) < 1 { + r.err = make([]error, 0) + } + + r.err = append(r.err, NewErrorTrace(code, msg, file, line, nil)) } func (r *DefaultReturn) AddParent(code int, msg string, file string, line int) { - // nothing + if len(r.err) < 1 { + r.err = make([]error, 0) + } + + r.err = append(r.err, NewErrorTrace(code, msg, file, line, nil)) } func (r DefaultReturn) JSON() []byte { @@ -94,5 +105,15 @@ func (r DefaultReturn) GinTonicErrorAbort(ctx *gin.Context, httpCode int) { Type: gin.ErrorTypeAny, }) + if len(r.err) > 0 { + for _, e := range r.err { + ctx.Errors = append(ctx.Errors, &gin.Error{ + //nolint #goerr113 + Err: goErr.New(e.Error()), + Type: gin.ErrorTypeAny, + }) + } + } + r.GinTonicAbort(ctx, httpCode) } diff --git a/go.mod b/go.mod index 6d1ebb57..13fad47b 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,11 @@ module github.com/nabbar/golib go 1.19 require ( - github.com/aws/aws-sdk-go-v2 v1.16.16 - github.com/aws/aws-sdk-go-v2/config v1.17.8 - github.com/aws/aws-sdk-go-v2/credentials v1.12.21 - github.com/aws/aws-sdk-go-v2/service/iam v1.18.20 - github.com/aws/aws-sdk-go-v2/service/s3 v1.28.0 + github.com/aws/aws-sdk-go-v2 v1.17.1 + github.com/aws/aws-sdk-go-v2/config v1.17.10 + github.com/aws/aws-sdk-go-v2/credentials v1.12.23 + github.com/aws/aws-sdk-go-v2/service/iam v1.18.22 + github.com/aws/aws-sdk-go-v2/service/s3 v1.29.1 github.com/bits-and-blooms/bitset v1.3.3 github.com/c-bata/go-prompt v0.2.6 github.com/fatih/color v1.13.0 @@ -29,14 +29,14 @@ require ( github.com/nats-io/jwt/v2 v2.3.0 github.com/nats-io/nats-server/v2 v2.9.3 github.com/nats-io/nats.go v1.18.0 - github.com/onsi/ginkgo/v2 v2.3.1 + github.com/onsi/ginkgo/v2 v2.4.0 github.com/onsi/gomega v1.22.1 github.com/pelletier/go-toml v1.9.5 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.13.0 github.com/shirou/gopsutil v3.21.11+incompatible github.com/sirupsen/logrus v1.9.0 - github.com/spf13/cobra v1.6.0 + github.com/spf13/cobra v1.6.1 github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/viper v1.13.0 github.com/vbauerster/mpb/v5 v5.4.0 @@ -44,7 +44,7 @@ require ( github.com/xhit/go-simple-mail v2.2.2+incompatible github.com/xujiajun/nutsdb v0.10.0 github.com/xujiajun/utils v0.0.0-20220904132955-5f7c5b914235 - golang.org/x/exp v0.0.0-20221019170559-20944726eadf + golang.org/x/exp v0.0.0-20221026004748-78e5e7837ae6 golang.org/x/net v0.1.0 golang.org/x/oauth2 v0.1.0 golang.org/x/sync v0.1.0 @@ -67,26 +67,26 @@ require ( github.com/Masterminds/semver v1.5.0 // indirect github.com/Masterminds/sprig v2.22.0+incompatible // indirect github.com/PuerkitoBio/goquery v1.8.0 // indirect - github.com/VictoriaMetrics/metrics v1.22.2 // indirect + github.com/VictoriaMetrics/metrics v1.23.0 // indirect github.com/VividCortex/ewma v1.2.0 // indirect github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect github.com/andybalholm/brotli v1.0.4 // indirect github.com/andybalholm/cascadia v1.3.1 // indirect github.com/armon/go-metrics v0.4.1 // indirect - github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.8 // indirect - github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.17 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.23 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.17 // indirect - github.com/aws/aws-sdk-go-v2/internal/ini v1.3.24 // indirect - github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.14 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.9 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.18 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.17 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.17 // indirect - github.com/aws/aws-sdk-go-v2/service/sso v1.11.23 // indirect - github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.6 // indirect - github.com/aws/aws-sdk-go-v2/service/sts v1.16.19 // indirect - github.com/aws/smithy-go v1.13.3 // indirect + github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.9 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.19 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.25 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.19 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.3.26 // indirect + github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.16 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.10 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.20 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.19 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.19 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.11.25 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.8 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.17.1 // indirect + github.com/aws/smithy-go v1.13.4 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bwmarrin/snowflake v0.3.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect @@ -100,6 +100,7 @@ require ( github.com/go-errors/errors v1.4.2 // indirect github.com/go-faster/city v1.0.1 // indirect github.com/go-faster/errors v0.6.1 // indirect + github.com/go-logr/logr v1.2.3 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect @@ -150,7 +151,7 @@ require ( github.com/mattn/go-runewidth v0.0.14 // indirect github.com/mattn/go-sqlite3 v1.14.15 // indirect github.com/mattn/go-tty v0.0.4 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/microsoft/go-mssqldb v0.17.0 // indirect github.com/miekg/dns v1.1.50 // indirect github.com/minio/highwayhash v1.0.2 // indirect @@ -194,7 +195,7 @@ require ( golang.org/x/mod v0.6.0 // indirect golang.org/x/text v0.4.0 // indirect golang.org/x/time v0.1.0 // indirect - golang.org/x/tools v0.1.12 // indirect + golang.org/x/tools v0.2.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect