From e86523adaee04def44a3e10363c43e861d50e3cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zapletal?= Date: Wed, 11 Oct 2023 10:24:36 +0200 Subject: [PATCH] fix(HMS-2757): improve unexpected rows error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukáš Zapletal --- internal/dao/pgx/pubkey_pgx.go | 6 +++--- internal/dao/pgx/reservation_pgx.go | 24 ++++++++++++------------ internal/dao/pgx/service_pgx.go | 2 +- internal/jobs/launch_instance_aws.go | 1 + 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/internal/dao/pgx/pubkey_pgx.go b/internal/dao/pgx/pubkey_pgx.go index 1aaf1b13..f105ce2b 100644 --- a/internal/dao/pgx/pubkey_pgx.go +++ b/internal/dao/pgx/pubkey_pgx.go @@ -88,7 +88,7 @@ func (x *pubkeyDao) Update(ctx context.Context, pubkey *models.Pubkey) error { return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil } @@ -132,7 +132,7 @@ func (x *pubkeyDao) Delete(ctx context.Context, id int64) error { return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil } @@ -191,7 +191,7 @@ func (x *pubkeyDao) UnscopedDeleteResource(ctx context.Context, id int64) error return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil } diff --git a/internal/dao/pgx/reservation_pgx.go b/internal/dao/pgx/reservation_pgx.go index 49f82e6c..0e581acc 100644 --- a/internal/dao/pgx/reservation_pgx.go +++ b/internal/dao/pgx/reservation_pgx.go @@ -61,7 +61,7 @@ func (x *reservationDao) CreateAWS(ctx context.Context, reservation *models.AWSR return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil @@ -92,7 +92,7 @@ func (x *reservationDao) CreateAzure(ctx context.Context, reservation *models.Az return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil @@ -123,7 +123,7 @@ func (x *reservationDao) CreateGCP(ctx context.Context, reservation *models.GCPR return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil @@ -168,7 +168,7 @@ func (x *reservationDao) CreateInstance(ctx context.Context, instance *models.Re return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil @@ -187,7 +187,7 @@ func (x *reservationDao) UpdateReservationInstance(ctx context.Context, reservat return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil @@ -308,7 +308,7 @@ func (x *reservationDao) UpdateStatus(ctx context.Context, id int64, status stri return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil } @@ -321,7 +321,7 @@ func (x *reservationDao) UnscopedUpdateAWSDetail(ctx context.Context, id int64, return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil } @@ -334,7 +334,7 @@ func (x *reservationDao) UpdateReservationIDForAWS(ctx context.Context, id int64 return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil } @@ -347,7 +347,7 @@ func (x *reservationDao) UpdateOperationNameForGCP(ctx context.Context, id int64 return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil } @@ -360,7 +360,7 @@ func (x *reservationDao) FinishWithSuccess(ctx context.Context, id int64) error return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil } @@ -373,7 +373,7 @@ func (x *reservationDao) FinishWithError(ctx context.Context, id int64, errorStr return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil } @@ -386,7 +386,7 @@ func (x *reservationDao) Delete(ctx context.Context, id int64) error { return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil } diff --git a/internal/dao/pgx/service_pgx.go b/internal/dao/pgx/service_pgx.go index 678ebd10..4f19477c 100644 --- a/internal/dao/pgx/service_pgx.go +++ b/internal/dao/pgx/service_pgx.go @@ -36,7 +36,7 @@ func UnscopedUpdatePubkey(ctx context.Context, pubkey *models.Pubkey) error { return fmt.Errorf("pgx error: %w", err) } if tag.RowsAffected() != 1 { - return fmt.Errorf("expected 1 row: %w", dao.ErrAffectedMismatch) + return fmt.Errorf("expected 1 row, got %d: %w", tag.RowsAffected(), dao.ErrAffectedMismatch) } return nil } diff --git a/internal/jobs/launch_instance_aws.go b/internal/jobs/launch_instance_aws.go index fbfffce3..d787e55e 100644 --- a/internal/jobs/launch_instance_aws.go +++ b/internal/jobs/launch_instance_aws.go @@ -181,6 +181,7 @@ func DoEnsurePubkeyOnAWS(ctx context.Context, args *LaunchInstanceAWSTaskArgs) e // update the AWS key name in reservation details awsReservation.Detail.PubkeyName = ec2Name + logger.Debug().Msgf("Updating AWS reservation detail %d", awsReservation.Reservation.ID) err = resDao.UnscopedUpdateAWSDetail(ctx, awsReservation.Reservation.ID, awsReservation.Detail) if err != nil { span.SetStatus(codes.Error, "failed to save AWS pubkey name to DB")