fix some errors
Re-working mongo.InsertError
This commit is contained in:
@@ -2,10 +2,11 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/CalebQ42/darkstorm-server/internal/backend"
|
||||
"github.com/google/uuid"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
@@ -39,32 +40,42 @@ func (m *MongoCrashTable) IsArchived(ind backend.IndividualCrash) bool {
|
||||
|
||||
func (m *MongoCrashTable) InsertCrash(ind backend.IndividualCrash) error {
|
||||
first, _, _ := strings.Cut(ind.Stack, "\n")
|
||||
_, err := m.col.UpdateOne(context.Background(),
|
||||
findRes := m.col.FindOne(context.Background(),
|
||||
bson.M{"error": ind.Error, "firstLine": first, //filter main report
|
||||
"individual.stack": ind.Stack, "individual.platform": ind.Platform}, //filter individual
|
||||
bson.M{"$inc": bson.M{"individual.count": 1}}, //increment count
|
||||
// bson.M{"$inc": bson.M{"individual.count": 1}}, //increment count
|
||||
)
|
||||
if err == mongo.ErrNoDocuments {
|
||||
ind.Count = 1
|
||||
_, err = m.col.UpdateOne(context.Background(),
|
||||
bson.M{"error": ind.Error, "firstLine": first}, //filter
|
||||
bson.M{"$push": bson.M{"individual": ind}}, //Add new individual report
|
||||
)
|
||||
if err == mongo.ErrNoDocuments {
|
||||
var id uuid.UUID
|
||||
id, err = uuid.NewV7()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = m.col.InsertOne(context.Background(),
|
||||
backend.CrashReport{
|
||||
ID: id.String(),
|
||||
Error: ind.Error,
|
||||
FirstLine: first,
|
||||
Individual: []backend.IndividualCrash{ind},
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
return err
|
||||
var out map[string]any
|
||||
findRes.Decode(&out)
|
||||
fmt.Println(out)
|
||||
return errors.New("STUFF")
|
||||
// if err != nil && err != mongo.ErrNoDocuments {
|
||||
// return err
|
||||
// }
|
||||
// if err == mongo.ErrNoDocuments || res.MatchedCount == 0 {
|
||||
// ind.Count = 1
|
||||
// res, err = m.col.UpdateMany(context.Background(),
|
||||
// bson.M{"error": ind.Error, "firstLine": first}, //filter
|
||||
// bson.M{"$push": bson.M{"individual": ind}}, //Add new individual report
|
||||
// )
|
||||
// if err != nil && err != mongo.ErrNoDocuments {
|
||||
// return err
|
||||
// }
|
||||
// if err == mongo.ErrNoDocuments || res.MatchedCount == 0 {
|
||||
// var id uuid.UUID
|
||||
// id, err = uuid.NewV7()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// _, err = m.col.InsertOne(context.Background(),
|
||||
// backend.CrashReport{
|
||||
// ID: id.String(),
|
||||
// Error: ind.Error,
|
||||
// FirstLine: first,
|
||||
// Individual: []backend.IndividualCrash{ind},
|
||||
// },
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user