diff --git a/save.go b/save.go index 3ac2757..594823e 100644 --- a/save.go +++ b/save.go @@ -242,14 +242,25 @@ func saveStruct( return nil } -func SaveMetaCollection(ctx context.Context, db *db.DBC, slice reflect.Value, ownerId uint32, removedIds meta.IRemovedIds, deltaSave bool) error { +func SaveMetaCollection( + ctx context.Context, + db *db.DBC, + slice reflect.Value, + ownerId uint32, + removedIds meta.IRemovedIds, + deltaSave bool, +) error { ctx, span := tracer.Start(ctx, "SaveMetaCollection") defer span.End() if slice.Type().Kind() != reflect.Slice { - return errors.Errorf("It isn't slice: %s", slice.Type().Kind()) + err := errors.Errorf("It isn't slice: %s", slice.Type().Kind()) + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) + return err } + sliceItem := reflect.New(slice.Type().Elem().Elem()) if sliceItem.Type().Kind() != reflect.Ptr { sliceItem = sliceItem.Addr() @@ -261,29 +272,42 @@ func SaveMetaCollection(ctx context.Context, db *db.DBC, slice reflect.Value, ow } if row == nil { - return errors.Errorf("Couldn't convert to IMetaStruct: %s", sliceItem.Kind()) + err := errors.Errorf("Couldn't convert to IMetaStruct: %s", sliceItem.Kind()) + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) + return err } item, _ := sliceItem.Interface().(meta.IMetaDataItem) if item == nil { - return errors.Errorf("Couldn't convert to IMetaDataItem: %s", slice.Type()) + err := errors.Errorf("Couldn't convert to IMetaDataItem: %s", slice.Type()) + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) + return err } if !deltaSave { cond := fmt.Sprintf("`%s`=%d ", item.GetOwnerFieldName(), ownerId) _, err := db.DeleteFrom(item.GetDbTableName()).Where(cond).Exec() if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) return err } } collection, err := NewDataCollection(db, ownerId, "", item) if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) return err } + for ind := 0; ind < slice.Len(); ind++ { ind_item, err := convertToIdataItem(slice.Index(ind)) if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) return err } // NOTE: we don't check here for error on purpose, here it's considered to be OK @@ -291,6 +315,8 @@ func SaveMetaCollection(ctx context.Context, db *db.DBC, slice reflect.Value, ow } if err := collection.Save(ctx); err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) return err } @@ -300,6 +326,8 @@ func SaveMetaCollection(ctx context.Context, db *db.DBC, slice reflect.Value, ow if removedIds.HasList(classId) { err := deleteByIds(db, ownerId, item, removedIds.GetList(classId)) if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) return err } }