updated mongo driver dependencies to v2
# Conflicts: # exerr/constructor.go # exerr/dataCategory.go # exerr/dataSeverity.go # exerr/dataType.go # exerr/exerr.go # go.mod # mongoext/registry.go # reflectext/primStrSer.go # rfctime/date.go # rfctime/rfc3339.go # rfctime/rfc3339Nano.go # rfctime/seconds.go # rfctime/unix.go # rfctime/unixMilli.go # rfctime/unixNano.go # wmo/collection.go # wmo/queryInsert.go
This commit is contained in:
+2
-2
@@ -16,7 +16,7 @@ import (
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
//
|
||||
@@ -253,7 +253,7 @@ func (b *Builder) Bytes(key string, val []byte) *Builder {
|
||||
return b.addMeta(key, MDTBytes, val)
|
||||
}
|
||||
|
||||
func (b *Builder) ObjectID(key string, val primitive.ObjectID) *Builder {
|
||||
func (b *Builder) ObjectID(key string, val bson.ObjectID) *Builder {
|
||||
return b.addMeta(key, MDTObjectID, val)
|
||||
}
|
||||
|
||||
|
||||
+9
-12
@@ -3,13 +3,14 @@ package exerr
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"maps"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
var reflectTypeStr = reflect.TypeOf("")
|
||||
var reflectTypeStr = reflect.TypeFor[string]()
|
||||
|
||||
func FromError(err error) *ExErr {
|
||||
|
||||
@@ -152,20 +153,18 @@ func getForeignMeta(err error) (mm MetaMap) {
|
||||
}()
|
||||
|
||||
rval := reflect.ValueOf(err)
|
||||
if rval.Kind() == reflect.Interface || rval.Kind() == reflect.Ptr {
|
||||
if rval.Kind() == reflect.Interface || rval.Kind() == reflect.Pointer {
|
||||
rval = reflect.ValueOf(err).Elem()
|
||||
}
|
||||
|
||||
mm.add("foreign.errortype", MDTString, rval.Type().String())
|
||||
|
||||
for k, v := range addMetaPrefix("foreign", getReflectedMetaValues(err, 8)) {
|
||||
mm[k] = v
|
||||
}
|
||||
maps.Copy(mm, addMetaPrefix("foreign", getReflectedMetaValues(err, 8)))
|
||||
|
||||
return mm
|
||||
}
|
||||
|
||||
func getReflectedMetaValues(value interface{}, remainingDepth int) map[string]MetaValue {
|
||||
func getReflectedMetaValues(value any, remainingDepth int) map[string]MetaValue {
|
||||
|
||||
if remainingDepth <= 0 {
|
||||
return map[string]MetaValue{}
|
||||
@@ -177,7 +176,7 @@ func getReflectedMetaValues(value interface{}, remainingDepth int) map[string]Me
|
||||
|
||||
rval := reflect.ValueOf(value)
|
||||
|
||||
if rval.Type().Kind() == reflect.Ptr {
|
||||
if rval.Type().Kind() == reflect.Pointer {
|
||||
|
||||
if rval.IsNil() {
|
||||
return map[string]MetaValue{"*": {DataType: MDTNil, Value: nil}}
|
||||
@@ -223,7 +222,7 @@ func getReflectedMetaValues(value interface{}, remainingDepth int) map[string]Me
|
||||
return map[string]MetaValue{"": {DataType: MDTIntArray, Value: ifraw}}
|
||||
case []int32:
|
||||
return map[string]MetaValue{"": {DataType: MDTInt32Array, Value: ifraw}}
|
||||
case primitive.ObjectID:
|
||||
case bson.ObjectID:
|
||||
return map[string]MetaValue{"": {DataType: MDTObjectID, Value: ifraw}}
|
||||
case []string:
|
||||
return map[string]MetaValue{"": {DataType: MDTStringArray, Value: ifraw}}
|
||||
@@ -237,9 +236,7 @@ func getReflectedMetaValues(value interface{}, remainingDepth int) map[string]Me
|
||||
fieldname := fieldtype.Name
|
||||
|
||||
if fieldtype.IsExported() {
|
||||
for k, v := range addMetaPrefix(fieldname, getReflectedMetaValues(rval.Field(i).Interface(), remainingDepth-1)) {
|
||||
m[k] = v
|
||||
}
|
||||
maps.Copy(m, addMetaPrefix(fieldname, getReflectedMetaValues(rval.Field(i).Interface(), remainingDepth-1)))
|
||||
}
|
||||
}
|
||||
return m
|
||||
|
||||
+9
-44
@@ -4,11 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/bsoncodec"
|
||||
"go.mongodb.org/mongo-driver/bson/bsonrw"
|
||||
"go.mongodb.org/mongo-driver/bson/bsontype"
|
||||
"reflect"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type ErrorCategory struct{ Category string }
|
||||
@@ -28,8 +24,8 @@ func (e ErrorCategory) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(e.Category)
|
||||
}
|
||||
|
||||
func (e *ErrorCategory) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
|
||||
if bt == bson.TypeNull {
|
||||
func (e *ErrorCategory) UnmarshalBSONValue(bt byte, data []byte) error {
|
||||
if bson.Type(bt) == bson.TypeNull {
|
||||
// we can't set nil in UnmarshalBSONValue (so we use default(struct))
|
||||
// Use mongoext.CreateGoExtBsonRegistry if you need to unmarsh pointer values
|
||||
// https://stackoverflow.com/questions/75167597
|
||||
@@ -37,11 +33,11 @@ func (e *ErrorCategory) UnmarshalBSONValue(bt bsontype.Type, data []byte) error
|
||||
*e = ErrorCategory{}
|
||||
return nil
|
||||
}
|
||||
if bt != bson.TypeString {
|
||||
return errors.New(fmt.Sprintf("cannot unmarshal %v into String", bt))
|
||||
if bson.Type(bt) != bson.TypeString {
|
||||
return errors.New(fmt.Sprintf("cannot unmarshal %v into String", bson.Type(bt)))
|
||||
}
|
||||
var tt string
|
||||
err := bson.RawValue{Type: bt, Value: data}.Unmarshal(&tt)
|
||||
err := bson.RawValue{Type: bson.Type(bt), Value: data}.Unmarshal(&tt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -49,40 +45,9 @@ func (e *ErrorCategory) UnmarshalBSONValue(bt bsontype.Type, data []byte) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e ErrorCategory) MarshalBSONValue() (bsontype.Type, []byte, error) {
|
||||
return bson.MarshalValue(e.Category)
|
||||
}
|
||||
|
||||
func (e ErrorCategory) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if val.Kind() == reflect.Ptr && val.IsNil() {
|
||||
if !val.CanSet() {
|
||||
return errors.New("ValueUnmarshalerDecodeValue")
|
||||
}
|
||||
val.Set(reflect.New(val.Type().Elem()))
|
||||
}
|
||||
|
||||
tp, src, err := bsonrw.Copier{}.CopyValueToBytes(vr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if val.Kind() == reflect.Ptr && len(src) == 0 {
|
||||
val.Set(reflect.Zero(val.Type()))
|
||||
return nil
|
||||
}
|
||||
|
||||
err = e.UnmarshalBSONValue(tp, src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if val.Kind() == reflect.Ptr {
|
||||
val.Set(reflect.ValueOf(&e))
|
||||
} else {
|
||||
val.Set(reflect.ValueOf(e))
|
||||
}
|
||||
|
||||
return nil
|
||||
func (e ErrorCategory) MarshalBSONValue() (byte, []byte, error) {
|
||||
tp, data, err := bson.MarshalValue(e.Category)
|
||||
return byte(tp), data, err
|
||||
}
|
||||
|
||||
//goland:noinspection GoUnusedGlobalVariable
|
||||
|
||||
+9
-44
@@ -4,11 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/bsoncodec"
|
||||
"go.mongodb.org/mongo-driver/bson/bsonrw"
|
||||
"go.mongodb.org/mongo-driver/bson/bsontype"
|
||||
"reflect"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type ErrorSeverity struct{ Severity string }
|
||||
@@ -30,8 +26,8 @@ func (e ErrorSeverity) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(e.Severity)
|
||||
}
|
||||
|
||||
func (e *ErrorSeverity) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
|
||||
if bt == bson.TypeNull {
|
||||
func (e *ErrorSeverity) UnmarshalBSONValue(bt byte, data []byte) error {
|
||||
if bson.Type(bt) == bson.TypeNull {
|
||||
// we can't set nil in UnmarshalBSONValue (so we use default(struct))
|
||||
// Use mongoext.CreateGoExtBsonRegistry if you need to unmarsh pointer values
|
||||
// https://stackoverflow.com/questions/75167597
|
||||
@@ -39,11 +35,11 @@ func (e *ErrorSeverity) UnmarshalBSONValue(bt bsontype.Type, data []byte) error
|
||||
*e = ErrorSeverity{}
|
||||
return nil
|
||||
}
|
||||
if bt != bson.TypeString {
|
||||
return errors.New(fmt.Sprintf("cannot unmarshal %v into String", bt))
|
||||
if bson.Type(bt) != bson.TypeString {
|
||||
return errors.New(fmt.Sprintf("cannot unmarshal %v into String", bson.Type(bt)))
|
||||
}
|
||||
var tt string
|
||||
err := bson.RawValue{Type: bt, Value: data}.Unmarshal(&tt)
|
||||
err := bson.RawValue{Type: bson.Type(bt), Value: data}.Unmarshal(&tt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -51,40 +47,9 @@ func (e *ErrorSeverity) UnmarshalBSONValue(bt bsontype.Type, data []byte) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e ErrorSeverity) MarshalBSONValue() (bsontype.Type, []byte, error) {
|
||||
return bson.MarshalValue(e.Severity)
|
||||
}
|
||||
|
||||
func (e ErrorSeverity) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if val.Kind() == reflect.Ptr && val.IsNil() {
|
||||
if !val.CanSet() {
|
||||
return errors.New("ValueUnmarshalerDecodeValue")
|
||||
}
|
||||
val.Set(reflect.New(val.Type().Elem()))
|
||||
}
|
||||
|
||||
tp, src, err := bsonrw.Copier{}.CopyValueToBytes(vr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if val.Kind() == reflect.Ptr && len(src) == 0 {
|
||||
val.Set(reflect.Zero(val.Type()))
|
||||
return nil
|
||||
}
|
||||
|
||||
err = e.UnmarshalBSONValue(tp, src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if val.Kind() == reflect.Ptr {
|
||||
val.Set(reflect.ValueOf(&e))
|
||||
} else {
|
||||
val.Set(reflect.ValueOf(e))
|
||||
}
|
||||
|
||||
return nil
|
||||
func (e ErrorSeverity) MarshalBSONValue() (byte, []byte, error) {
|
||||
tp, data, err := bson.MarshalValue(e.Severity)
|
||||
return byte(tp), data, err
|
||||
}
|
||||
|
||||
//goland:noinspection GoUnusedGlobalVariable
|
||||
|
||||
+35
-71
@@ -4,14 +4,9 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/dataext"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/bsoncodec"
|
||||
"go.mongodb.org/mongo-driver/bson/bsonrw"
|
||||
"go.mongodb.org/mongo-driver/bson/bsontype"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type ErrorType struct {
|
||||
@@ -21,42 +16,42 @@ type ErrorType struct {
|
||||
|
||||
//goland:noinspection GoUnusedGlobalVariable
|
||||
var (
|
||||
TypeInternal = NewType("INTERNAL_ERROR", langext.Ptr(500))
|
||||
TypePanic = NewType("PANIC", langext.Ptr(500))
|
||||
TypeNotImplemented = NewType("NOT_IMPLEMENTED", langext.Ptr(500))
|
||||
TypeAssert = NewType("ASSERT", langext.Ptr(500))
|
||||
TypeInternal = NewType("INTERNAL_ERROR", new(500))
|
||||
TypePanic = NewType("PANIC", new(500))
|
||||
TypeNotImplemented = NewType("NOT_IMPLEMENTED", new(500))
|
||||
TypeAssert = NewType("ASSERT", new(500))
|
||||
|
||||
TypeMongoQuery = NewType("MONGO_QUERY", langext.Ptr(500))
|
||||
TypeCursorTokenDecode = NewType("CURSOR_TOKEN_DECODE", langext.Ptr(500))
|
||||
TypeMongoFilter = NewType("MONGO_FILTER", langext.Ptr(500))
|
||||
TypeMongoReflection = NewType("MONGO_REFLECTION", langext.Ptr(500))
|
||||
TypeMongoInvalidOpt = NewType("MONGO_INVALIDOPT", langext.Ptr(500))
|
||||
TypeMongoQuery = NewType("MONGO_QUERY", new(500))
|
||||
TypeCursorTokenDecode = NewType("CURSOR_TOKEN_DECODE", new(500))
|
||||
TypeMongoFilter = NewType("MONGO_FILTER", new(500))
|
||||
TypeMongoReflection = NewType("MONGO_REFLECTION", new(500))
|
||||
TypeMongoInvalidOpt = NewType("MONGO_INVALIDOPT", new(500))
|
||||
|
||||
TypeSQLQuery = NewType("SQL_QUERY", langext.Ptr(500))
|
||||
TypeSQLBuild = NewType("SQL_BUILD", langext.Ptr(500))
|
||||
TypeSQLDecode = NewType("SQL_DECODE", langext.Ptr(500))
|
||||
TypeSQLQuery = NewType("SQL_QUERY", new(500))
|
||||
TypeSQLBuild = NewType("SQL_BUILD", new(500))
|
||||
TypeSQLDecode = NewType("SQL_DECODE", new(500))
|
||||
|
||||
TypeWrap = NewType("Wrap", nil)
|
||||
|
||||
TypeBindFailURI = NewType("BINDFAIL_URI", langext.Ptr(400))
|
||||
TypeBindFailQuery = NewType("BINDFAIL_QUERY", langext.Ptr(400))
|
||||
TypeBindFailJSON = NewType("BINDFAIL_JSON", langext.Ptr(400))
|
||||
TypeBindFailFormData = NewType("BINDFAIL_FORMDATA", langext.Ptr(400))
|
||||
TypeBindFailHeader = NewType("BINDFAIL_HEADER", langext.Ptr(400))
|
||||
TypeBindFailURI = NewType("BINDFAIL_URI", new(400))
|
||||
TypeBindFailQuery = NewType("BINDFAIL_QUERY", new(400))
|
||||
TypeBindFailJSON = NewType("BINDFAIL_JSON", new(400))
|
||||
TypeBindFailFormData = NewType("BINDFAIL_FORMDATA", new(400))
|
||||
TypeBindFailHeader = NewType("BINDFAIL_HEADER", new(400))
|
||||
|
||||
TypeMarshalEntityID = NewType("MARSHAL_ENTITY_ID", langext.Ptr(400))
|
||||
TypeInvalidCSID = NewType("INVALID_CSID", langext.Ptr(400))
|
||||
TypeMarshalEntityID = NewType("MARSHAL_ENTITY_ID", new(400))
|
||||
TypeInvalidCSID = NewType("INVALID_CSID", new(400))
|
||||
|
||||
TypeGoogleStatuscode = NewType("GOOGLE_STATUSCODE", langext.Ptr(400))
|
||||
TypeGoogleResponse = NewType("GOOGLE_RESPONSE", langext.Ptr(400))
|
||||
TypeGoogleStatuscode = NewType("GOOGLE_STATUSCODE", new(400))
|
||||
TypeGoogleResponse = NewType("GOOGLE_RESPONSE", new(400))
|
||||
|
||||
TypeUnauthorized = NewType("UNAUTHORIZED", langext.Ptr(401))
|
||||
TypeAuthFailed = NewType("AUTH_FAILED", langext.Ptr(401))
|
||||
TypeUnauthorized = NewType("UNAUTHORIZED", new(401))
|
||||
TypeAuthFailed = NewType("AUTH_FAILED", new(401))
|
||||
|
||||
TypeInvalidImage = NewType("IMAGEEXT_INVALID_IMAGE", langext.Ptr(400))
|
||||
TypeInvalidMimeType = NewType("IMAGEEXT_INVALID_MIMETYPE", langext.Ptr(400))
|
||||
TypeInvalidImage = NewType("IMAGEEXT_INVALID_IMAGE", new(400))
|
||||
TypeInvalidMimeType = NewType("IMAGEEXT_INVALID_MIMETYPE", new(400))
|
||||
|
||||
TypeWebsocket = NewType("WEBSOCKET", langext.Ptr(500))
|
||||
TypeWebsocket = NewType("WEBSOCKET", new(500))
|
||||
|
||||
// other values come from the downstream application that uses goext
|
||||
)
|
||||
@@ -81,8 +76,8 @@ func (e ErrorType) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(e.Key)
|
||||
}
|
||||
|
||||
func (e *ErrorType) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
|
||||
if bt == bson.TypeNull {
|
||||
func (e *ErrorType) UnmarshalBSONValue(bt byte, data []byte) error {
|
||||
if bson.Type(bt) == bson.TypeNull {
|
||||
// we can't set nil in UnmarshalBSONValue (so we use default(struct))
|
||||
// Use mongoext.CreateGoExtBsonRegistry if you need to unmarsh pointer values
|
||||
// https://stackoverflow.com/questions/75167597
|
||||
@@ -90,11 +85,11 @@ func (e *ErrorType) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
|
||||
*e = ErrorType{}
|
||||
return nil
|
||||
}
|
||||
if bt != bson.TypeString {
|
||||
return errors.New(fmt.Sprintf("cannot unmarshal %v into String", bt))
|
||||
if bson.Type(bt) != bson.TypeString {
|
||||
return errors.New(fmt.Sprintf("cannot unmarshal %v into String", bson.Type(bt)))
|
||||
}
|
||||
var tt string
|
||||
err := bson.RawValue{Type: bt, Value: data}.Unmarshal(&tt)
|
||||
err := bson.RawValue{Type: bson.Type(bt), Value: data}.Unmarshal(&tt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -108,40 +103,9 @@ func (e *ErrorType) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (e ErrorType) MarshalBSONValue() (bsontype.Type, []byte, error) {
|
||||
return bson.MarshalValue(e.Key)
|
||||
}
|
||||
|
||||
func (e ErrorType) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
|
||||
if val.Kind() == reflect.Ptr && val.IsNil() {
|
||||
if !val.CanSet() {
|
||||
return errors.New("ValueUnmarshalerDecodeValue")
|
||||
}
|
||||
val.Set(reflect.New(val.Type().Elem()))
|
||||
}
|
||||
|
||||
tp, src, err := bsonrw.Copier{}.CopyValueToBytes(vr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if val.Kind() == reflect.Ptr && len(src) == 0 {
|
||||
val.Set(reflect.Zero(val.Type()))
|
||||
return nil
|
||||
}
|
||||
|
||||
err = e.UnmarshalBSONValue(tp, src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if val.Kind() == reflect.Ptr {
|
||||
val.Set(reflect.ValueOf(&e))
|
||||
} else {
|
||||
val.Set(reflect.ValueOf(e))
|
||||
}
|
||||
|
||||
return nil
|
||||
func (e ErrorType) MarshalBSONValue() (byte, []byte, error) {
|
||||
tp, data, err := bson.MarshalValue(e.Key)
|
||||
return byte(tp), data, err
|
||||
}
|
||||
|
||||
var registeredTypes = dataext.SyncMap[string, ErrorType]{}
|
||||
|
||||
+14
-15
@@ -3,10 +3,9 @@ package exerr
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/tst"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -57,7 +56,7 @@ func TestBSONMarshalErrorCategory(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 350*time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
client, err := mongo.Connect(ctx)
|
||||
client, err := mongo.Connect()
|
||||
if err != nil {
|
||||
t.Skip("Skip test - no local mongo found")
|
||||
return
|
||||
@@ -68,7 +67,7 @@ func TestBSONMarshalErrorCategory(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
primimd := primitive.NewObjectID()
|
||||
primimd := bson.NewObjectID()
|
||||
|
||||
_, err = client.Database("_test").Collection("goext-cicd").InsertOne(ctx, bson.M{"_id": primimd, "val": CatSystem})
|
||||
tst.AssertNoErr(t, err)
|
||||
@@ -76,8 +75,8 @@ func TestBSONMarshalErrorCategory(t *testing.T) {
|
||||
cursor := client.Database("_test").Collection("goext-cicd").FindOne(ctx, bson.M{"_id": primimd, "val": bson.M{"$type": "string"}})
|
||||
|
||||
var c1 struct {
|
||||
ID primitive.ObjectID `bson:"_id"`
|
||||
Val ErrorCategory `bson:"val"`
|
||||
ID bson.ObjectID `bson:"_id"`
|
||||
Val ErrorCategory `bson:"val"`
|
||||
}
|
||||
|
||||
err = cursor.Decode(&c1)
|
||||
@@ -90,7 +89,7 @@ func TestBSONMarshalErrorSeverity(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 350*time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
client, err := mongo.Connect(ctx)
|
||||
client, err := mongo.Connect()
|
||||
if err != nil {
|
||||
t.Skip("Skip test - no local mongo found")
|
||||
return
|
||||
@@ -101,7 +100,7 @@ func TestBSONMarshalErrorSeverity(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
primimd := primitive.NewObjectID()
|
||||
primimd := bson.NewObjectID()
|
||||
|
||||
_, err = client.Database("_test").Collection("goext-cicd").InsertOne(ctx, bson.M{"_id": primimd, "val": SevErr})
|
||||
tst.AssertNoErr(t, err)
|
||||
@@ -109,8 +108,8 @@ func TestBSONMarshalErrorSeverity(t *testing.T) {
|
||||
cursor := client.Database("_test").Collection("goext-cicd").FindOne(ctx, bson.M{"_id": primimd, "val": bson.M{"$type": "string"}})
|
||||
|
||||
var c1 struct {
|
||||
ID primitive.ObjectID `bson:"_id"`
|
||||
Val ErrorSeverity `bson:"val"`
|
||||
ID bson.ObjectID `bson:"_id"`
|
||||
Val ErrorSeverity `bson:"val"`
|
||||
}
|
||||
|
||||
err = cursor.Decode(&c1)
|
||||
@@ -123,7 +122,7 @@ func TestBSONMarshalErrorType(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 350*time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
client, err := mongo.Connect(ctx)
|
||||
client, err := mongo.Connect()
|
||||
if err != nil {
|
||||
t.Skip("Skip test - no local mongo found")
|
||||
return
|
||||
@@ -134,7 +133,7 @@ func TestBSONMarshalErrorType(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
primimd := primitive.NewObjectID()
|
||||
primimd := bson.NewObjectID()
|
||||
|
||||
_, err = client.Database("_test").Collection("goext-cicd").InsertOne(ctx, bson.M{"_id": primimd, "val": TypeNotImplemented})
|
||||
tst.AssertNoErr(t, err)
|
||||
@@ -142,8 +141,8 @@ func TestBSONMarshalErrorType(t *testing.T) {
|
||||
cursor := client.Database("_test").Collection("goext-cicd").FindOne(ctx, bson.M{"_id": primimd, "val": bson.M{"$type": "string"}})
|
||||
|
||||
var c1 struct {
|
||||
ID primitive.ObjectID `bson:"_id"`
|
||||
Val ErrorType `bson:"val"`
|
||||
ID bson.ObjectID `bson:"_id"`
|
||||
Val ErrorType `bson:"val"`
|
||||
}
|
||||
|
||||
err = cursor.Decode(&c1)
|
||||
|
||||
+32
-30
@@ -2,9 +2,9 @@ package exerr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"github.com/rs/xid"
|
||||
"github.com/rs/zerolog"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -125,35 +125,37 @@ func (ee *ExErr) FormatLog(lvl LogPrintLevel) string {
|
||||
|
||||
} else if lvl == LogPrintOverview {
|
||||
|
||||
str := "[" + ee.RecursiveType().Key + "] <" + ee.UniqueID + "> " + strings.ReplaceAll(ee.RecursiveMessage(), "\n", " ") + "\n"
|
||||
var str strings.Builder
|
||||
str.WriteString("[" + ee.RecursiveType().Key + "] <" + ee.UniqueID + "> " + strings.ReplaceAll(ee.RecursiveMessage(), "\n", " ") + "\n")
|
||||
|
||||
for exk, exv := range ee.Extra {
|
||||
str += fmt.Sprintf(" # [[[ %s ==> %v ]]]\n", exk, exv)
|
||||
str.WriteString(fmt.Sprintf(" # [[[ %s ==> %v ]]]\n", exk, exv))
|
||||
}
|
||||
|
||||
indent := ""
|
||||
var indent strings.Builder
|
||||
for curr := ee; curr != nil; curr = curr.OriginalError {
|
||||
indent += " "
|
||||
indent.WriteString(" ")
|
||||
|
||||
str += indent
|
||||
str += "-> "
|
||||
str.WriteString(indent.String())
|
||||
str.WriteString("-> ")
|
||||
strmsg := strings.Trim(curr.Message, " \r\n\t")
|
||||
if lbidx := strings.Index(curr.Message, "\n"); lbidx >= 0 {
|
||||
strmsg = strmsg[0:lbidx]
|
||||
}
|
||||
strmsg = langext.StrLimit(strmsg, 61, "...")
|
||||
str += strmsg
|
||||
str += "\n"
|
||||
str.WriteString(strmsg)
|
||||
str.WriteString("\n")
|
||||
|
||||
}
|
||||
return str
|
||||
return str.String()
|
||||
|
||||
} else if lvl == LogPrintFull {
|
||||
|
||||
str := "[" + ee.RecursiveType().Key + "] <" + ee.UniqueID + "> " + strings.ReplaceAll(ee.RecursiveMessage(), "\n", " ") + "\n"
|
||||
var str strings.Builder
|
||||
str.WriteString("[" + ee.RecursiveType().Key + "] <" + ee.UniqueID + "> " + strings.ReplaceAll(ee.RecursiveMessage(), "\n", " ") + "\n")
|
||||
|
||||
for exk, exv := range ee.Extra {
|
||||
str += fmt.Sprintf(" # [[[ %s ==> %v ]]]\n", exk, exv)
|
||||
str.WriteString(fmt.Sprintf(" # [[[ %s ==> %v ]]]\n", exk, exv))
|
||||
}
|
||||
|
||||
indent := ""
|
||||
@@ -165,33 +167,33 @@ func (ee *ExErr) FormatLog(lvl LogPrintLevel) string {
|
||||
etype = "~"
|
||||
}
|
||||
|
||||
str += indent
|
||||
str += "-> ["
|
||||
str += etype
|
||||
str.WriteString(indent)
|
||||
str.WriteString("-> [")
|
||||
str.WriteString(etype)
|
||||
if curr.Category == CatForeign {
|
||||
str += "|Foreign"
|
||||
str.WriteString("|Foreign")
|
||||
}
|
||||
str += "] "
|
||||
str += strings.ReplaceAll(curr.Message, "\n", " ")
|
||||
str.WriteString("] ")
|
||||
str.WriteString(strings.ReplaceAll(curr.Message, "\n", " "))
|
||||
if curr.Caller != "" {
|
||||
str += " (@ "
|
||||
str += curr.Caller
|
||||
str += ")"
|
||||
str.WriteString(" (@ ")
|
||||
str.WriteString(curr.Caller)
|
||||
str.WriteString(")")
|
||||
}
|
||||
str += "\n"
|
||||
str.WriteString("\n")
|
||||
|
||||
if curr.Meta.Any() {
|
||||
meta := indent + " {" + curr.Meta.FormatOneLine(240) + "}"
|
||||
if len(meta) < 200 {
|
||||
str += meta
|
||||
str += "\n"
|
||||
str.WriteString(meta)
|
||||
str.WriteString("\n")
|
||||
} else {
|
||||
str += curr.Meta.FormatMultiLine(indent+" ", " ", 1024)
|
||||
str += "\n"
|
||||
str.WriteString(curr.Meta.FormatMultiLine(indent+" ", " ", 1024))
|
||||
str.WriteString("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
return str
|
||||
return str.String()
|
||||
|
||||
} else {
|
||||
|
||||
@@ -201,7 +203,7 @@ func (ee *ExErr) FormatLog(lvl LogPrintLevel) string {
|
||||
}
|
||||
|
||||
func (ee *ExErr) ShortLog(evt *zerolog.Event) {
|
||||
ee.Meta.Apply(evt, langext.Ptr(240)).Msg(ee.FormatLog(LogPrintShort))
|
||||
ee.Meta.Apply(evt, new(240)).Msg(ee.FormatLog(LogPrintShort))
|
||||
}
|
||||
|
||||
// RecursiveMessage returns the message to show
|
||||
@@ -254,7 +256,7 @@ func (ee *ExErr) RecursiveType() ErrorType {
|
||||
func (ee *ExErr) RecursiveStatuscode() *int {
|
||||
for curr := ee; curr != nil; curr = curr.OriginalError {
|
||||
if curr.StatusCode != nil {
|
||||
return langext.Ptr(*curr.StatusCode)
|
||||
return new(*curr.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,7 +281,7 @@ func (ee *ExErr) RecursiveCategory() ErrorCategory {
|
||||
func (ee *ExErr) RecursiveMeta(key string) *MetaValue {
|
||||
for curr := ee; curr != nil; curr = curr.OriginalError {
|
||||
if metaval, ok := curr.Meta[key]; ok {
|
||||
return langext.Ptr(metaval)
|
||||
return new(metaval)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-10
@@ -7,8 +7,7 @@ import (
|
||||
"fmt"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"github.com/rs/zerolog"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -99,7 +98,7 @@ func (v MetaValue) SerializeValue() (string, error) {
|
||||
case MDTBytes:
|
||||
return hex.EncodeToString(v.Value.([]byte)), nil
|
||||
case MDTObjectID:
|
||||
return v.Value.(primitive.ObjectID).Hex(), nil
|
||||
return v.Value.(bson.ObjectID).Hex(), nil
|
||||
case MDTTime:
|
||||
return strconv.FormatInt(v.Value.(time.Time).Unix(), 10) + "|" + strconv.FormatInt(int64(v.Value.(time.Time).Nanosecond()), 10), nil
|
||||
case MDTDuration:
|
||||
@@ -178,7 +177,7 @@ func (v MetaValue) ShortString(lim int) string {
|
||||
case MDTBytes:
|
||||
return langext.StrLimit(hex.EncodeToString(v.Value.([]byte)), lim, "...")
|
||||
case MDTObjectID:
|
||||
return v.Value.(primitive.ObjectID).Hex()
|
||||
return v.Value.(bson.ObjectID).Hex()
|
||||
case MDTTime:
|
||||
return v.Value.(time.Time).Format(time.RFC3339)
|
||||
case MDTDuration:
|
||||
@@ -266,7 +265,7 @@ func (v MetaValue) Apply(key string, evt *zerolog.Event, limitLen *int) *zerolog
|
||||
case MDTBytes:
|
||||
return evt.Bytes(key, v.Value.([]byte))
|
||||
case MDTObjectID:
|
||||
return evt.Str(key, v.Value.(primitive.ObjectID).Hex())
|
||||
return evt.Str(key, v.Value.(bson.ObjectID).Hex())
|
||||
case MDTTime:
|
||||
return evt.Time(key, v.Value.(time.Time))
|
||||
case MDTDuration:
|
||||
@@ -460,7 +459,7 @@ func (v *MetaValue) Deserialize(value string, datatype metaDataType) error {
|
||||
v.DataType = datatype
|
||||
return nil
|
||||
case MDTObjectID:
|
||||
r, err := primitive.ObjectIDFromHex(value)
|
||||
r, err := bson.ObjectIDFromHex(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -577,7 +576,7 @@ func (v MetaValue) ValueString() string {
|
||||
case MDTBytes:
|
||||
return hex.EncodeToString(v.Value.([]byte))
|
||||
case MDTObjectID:
|
||||
return v.Value.(primitive.ObjectID).Hex()
|
||||
return v.Value.(bson.ObjectID).Hex()
|
||||
case MDTTime:
|
||||
return v.Value.(time.Time).Format(time.RFC3339Nano)
|
||||
case MDTDuration:
|
||||
@@ -628,8 +627,8 @@ func (v MetaValue) rawValueForJson() any {
|
||||
if v.Value.(AnyWrap).IsError {
|
||||
return bson.M{"@error": true}
|
||||
}
|
||||
jsonobj := primitive.M{}
|
||||
jsonarr := primitive.A{}
|
||||
jsonobj := bson.M{}
|
||||
jsonarr := bson.A{}
|
||||
if err := json.Unmarshal([]byte(v.Value.(AnyWrap).Json), &jsonobj); err == nil {
|
||||
return jsonobj
|
||||
} else if err := json.Unmarshal([]byte(v.Value.(AnyWrap).Json), &jsonarr); err == nil {
|
||||
@@ -654,7 +653,7 @@ func (v MetaValue) rawValueForJson() any {
|
||||
return v.Value.(time.Time).Format(time.RFC3339Nano)
|
||||
}
|
||||
if v.DataType == MDTObjectID {
|
||||
return v.Value.(primitive.ObjectID).Hex()
|
||||
return v.Value.(bson.ObjectID).Hex()
|
||||
}
|
||||
if v.DataType == MDTNil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user