Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(HMS-2757): improve unexpected row error #706

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -53,7 +53,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 @@ -84,7 +84,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 @@ -115,7 +115,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 @@ -160,7 +160,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 @@ -179,7 +179,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 @@ -300,7 +300,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 @@ -313,7 +313,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 @@ -326,7 +326,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 @@ -339,7 +339,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 @@ -352,7 +352,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 @@ -365,7 +365,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 @@ -378,7 +378,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