Skip to content

Commit

Permalink
fix: wrap errors properly in data access
Browse files Browse the repository at this point in the history
See: BEDS-94
  • Loading branch information
LuccaBitfly committed Oct 30, 2024
1 parent bfe90b8 commit e330d67
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion backend/pkg/api/data_access/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (d *DataAccessService) UpdateValidatorDashboardsArchiving(ctx context.Conte

query, args, err := ds.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

_, err = d.writerDb.ExecContext(ctx, query, args...)
Expand Down
16 changes: 8 additions & 8 deletions backend/pkg/api/data_access/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ func (d *DataAccessService) UpdateNotificationSettingsGeneral(ctx context.Contex

query, args, err := insertDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

_, err = tx.ExecContext(ctx, query, args...)
Expand All @@ -1361,7 +1361,7 @@ func (d *DataAccessService) UpdateNotificationSettingsGeneral(ctx context.Contex

query, args, err := deleteDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

_, err = tx.ExecContext(ctx, query, args...)
Expand Down Expand Up @@ -1422,7 +1422,7 @@ func (d *DataAccessService) UpdateNotificationSettingsNetworks(ctx context.Conte

query, args, err := insertDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

_, err = tx.ExecContext(ctx, query, args...)
Expand All @@ -1439,7 +1439,7 @@ func (d *DataAccessService) UpdateNotificationSettingsNetworks(ctx context.Conte

query, args, err := deleteDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

_, err = tx.ExecContext(ctx, query, args...)
Expand Down Expand Up @@ -1964,7 +1964,7 @@ func (d *DataAccessService) UpdateNotificationSettingsValidatorDashboard(ctx con

query, args, err := insertDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

_, err = tx.ExecContext(ctx, query, args...)
Expand All @@ -1981,7 +1981,7 @@ func (d *DataAccessService) UpdateNotificationSettingsValidatorDashboard(ctx con

query, args, err := deleteDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

_, err = tx.ExecContext(ctx, query, args...)
Expand Down Expand Up @@ -2052,7 +2052,7 @@ func (d *DataAccessService) UpdateNotificationSettingsAccountDashboard(ctx conte

// query, args, err := insertDs.Prepared(true).ToSQL()
// if err != nil {
// return fmt.Errorf("error preparing query: %v", err)
// return fmt.Errorf("error preparing query: %w", err)
// }

// _, err = tx.ExecContext(ctx, query, args...)
Expand All @@ -2069,7 +2069,7 @@ func (d *DataAccessService) UpdateNotificationSettingsAccountDashboard(ctx conte

// query, args, err := deleteDs.Prepared(true).ToSQL()
// if err != nil {
// return fmt.Errorf("error preparing query: %v", err)
// return fmt.Errorf("error preparing query: %w", err)
// }

// _, err = tx.ExecContext(ctx, query, args...)
Expand Down
40 changes: 20 additions & 20 deletions backend/pkg/api/data_access/vdb_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,12 @@ func (d *DataAccessService) GetValidatorDashboardRewards(ctx context.Context, da
wg.Go(func() error {
query, args, err := rewardsDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

err = d.clickhouseReader.SelectContext(ctx, &queryResult, query, args...)
if err != nil {
return fmt.Errorf("error retrieving rewards data: %v", err)
return fmt.Errorf("error retrieving rewards data: %w", err)
}
return nil
})
Expand All @@ -334,12 +334,12 @@ func (d *DataAccessService) GetValidatorDashboardRewards(ctx context.Context, da

query, args, err := elDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

err = d.readerDb.SelectContext(ctx, &elQueryResult, query, args...)
if err != nil {
return fmt.Errorf("error retrieving el rewards data for rewards: %v", err)
return fmt.Errorf("error retrieving el rewards data for rewards: %w", err)
}

for _, entry := range elQueryResult {
Expand All @@ -353,7 +353,7 @@ func (d *DataAccessService) GetValidatorDashboardRewards(ctx context.Context, da

err = wg.Wait()
if err != nil {
return nil, nil, fmt.Errorf("error retrieving validator dashboard rewards data: %v", err)
return nil, nil, fmt.Errorf("error retrieving validator dashboard rewards data: %w", err)
}

// ------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -625,12 +625,12 @@ func (d *DataAccessService) GetValidatorDashboardGroupRewards(ctx context.Contex
wg.Go(func() error {
query, args, err := rewardsDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

err = d.clickhouseReader.SelectContext(ctx, &queryResult, query, args...)
if err != nil {
return fmt.Errorf("error retrieving group rewards data: %v", err)
return fmt.Errorf("error retrieving group rewards data: %w", err)
}
return nil
})
Expand All @@ -641,19 +641,19 @@ func (d *DataAccessService) GetValidatorDashboardGroupRewards(ctx context.Contex
wg.Go(func() error {
query, args, err := elDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

err = d.readerDb.GetContext(ctx, &elRewards, query, args...)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return fmt.Errorf("error retrieving el rewards data for group rewards: %v", err)
return fmt.Errorf("error retrieving el rewards data for group rewards: %w", err)
}
return nil
})

err := wg.Wait()
if err != nil {
return nil, fmt.Errorf("error retrieving validator dashboard group rewards data: %v", err)
return nil, fmt.Errorf("error retrieving validator dashboard group rewards data: %w", err)
}

// ------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -800,12 +800,12 @@ func (d *DataAccessService) GetValidatorDashboardRewardsChart(ctx context.Contex
wg.Go(func() error {
query, args, err := rewardsDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

err = d.clickhouseReader.SelectContext(ctx, &queryResult, query, args...)
if err != nil {
return fmt.Errorf("error retrieving rewards chart data: %v", err)
return fmt.Errorf("error retrieving rewards chart data: %w", err)
}
return nil
})
Expand All @@ -822,12 +822,12 @@ func (d *DataAccessService) GetValidatorDashboardRewardsChart(ctx context.Contex

query, args, err := elDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

err = d.readerDb.SelectContext(ctx, &elQueryResult, query, args...)
if err != nil {
return fmt.Errorf("error retrieving el rewards data for rewards chart: %v", err)
return fmt.Errorf("error retrieving el rewards data for rewards chart: %w", err)
}

for _, entry := range elQueryResult {
Expand All @@ -841,7 +841,7 @@ func (d *DataAccessService) GetValidatorDashboardRewardsChart(ctx context.Contex

err := wg.Wait()
if err != nil {
return nil, fmt.Errorf("error retrieving validator dashboard rewards chart data: %v", err)
return nil, fmt.Errorf("error retrieving validator dashboard rewards chart data: %w", err)
}

// ------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1065,12 +1065,12 @@ func (d *DataAccessService) GetValidatorDashboardDuties(ctx context.Context, das
wg.Go(func() error {
query, args, err := rewardsDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

err = d.clickhouseReader.SelectContext(ctx, &queryResult, query, args...)
if err != nil {
return fmt.Errorf("error retrieving validator rewards data: %v", err)
return fmt.Errorf("error retrieving validator rewards data: %w", err)
}
return nil
})
Expand All @@ -1086,12 +1086,12 @@ func (d *DataAccessService) GetValidatorDashboardDuties(ctx context.Context, das

query, args, err := elDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %v", err)
return fmt.Errorf("error preparing query: %w", err)
}

err = d.readerDb.SelectContext(ctx, &elQueryResult, query, args...)
if err != nil {
return fmt.Errorf("error retrieving validator el rewards data for rewards: %v", err)
return fmt.Errorf("error retrieving validator el rewards data for rewards: %w", err)
}

for _, entry := range elQueryResult {
Expand All @@ -1102,7 +1102,7 @@ func (d *DataAccessService) GetValidatorDashboardDuties(ctx context.Context, das

err = wg.Wait()
if err != nil {
return nil, nil, fmt.Errorf("error retrieving validator dashboard rewards data: %v", err)
return nil, nil, fmt.Errorf("error retrieving validator dashboard rewards data: %w", err)
}

// ------------------------------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit e330d67

Please sign in to comment.