Skip to content

Commit

Permalink
fix(HMS-2757): improve unexpected rows error
Browse files Browse the repository at this point in the history
Signed-off-by: Lukáš Zapletal <[email protected]>
  • Loading branch information
lzap authored and ezr-ondrej committed Oct 11, 2023
1 parent 58de839 commit e86523a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
6 changes: 3 additions & 3 deletions internal/dao/pgx/pubkey_pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
24 changes: 12 additions & 12 deletions internal/dao/pgx/reservation_pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/dao/pgx/service_pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions internal/jobs/launch_instance_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e86523a

Please sign in to comment.