Skip to content

Commit

Permalink
Fix error handling in corrector.go to catch all the err in defer func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
ykadowak committed Nov 8, 2023
1 parent fae30a0 commit 94d5157
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions pkg/index/job/correction/service/corrector.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,14 @@ func (c *correct) correct(ctx context.Context) (err error) {
curTargetAgent := 0
jobErrs := make([]error, 0, c.cfg.Corrector.StreamListConcurrency)

Check warning on line 164 in pkg/index/job/correction/service/corrector.go

View check run for this annotation

Codecov / codecov/patch

pkg/index/job/correction/service/corrector.go#L164

Added line #L164 was not covered by tests
if err := c.discoverer.GetClient().OrderedRange(ctx, c.agentAddrs,
func(ctx context.Context, addr string, conn *grpc.ClientConn, copts ...grpc.CallOption) error {
func(ctx context.Context, addr string, conn *grpc.ClientConn, copts ...grpc.CallOption) (err error) {

Check warning on line 166 in pkg/index/job/correction/service/corrector.go

View check run for this annotation

Codecov / codecov/patch

pkg/index/job/correction/service/corrector.go#L166

Added line #L166 was not covered by tests
// current address is the leftAgentAddrs[0] because this is OrderedRange and
// leftAgentAddrs is copied from c.agentAddrs
defer func() {
if err != nil {
// catch the err that happend in this scope using named return err
jobErrs = append(jobErrs, err)
}

Check warning on line 173 in pkg/index/job/correction/service/corrector.go

View check run for this annotation

Codecov / codecov/patch

pkg/index/job/correction/service/corrector.go#L170-L173

Added lines #L170 - L173 were not covered by tests
curTargetAgent++
}()

Expand All @@ -187,7 +191,6 @@ func (c *correct) correct(ctx context.Context) (err error) {
vc := vald.NewValdClient(conn)
stream, err := vc.StreamListObject(ctx, &payload.Object_List_Request{})
if err != nil {
jobErrs = append(jobErrs, err)
return err
}

Expand Down Expand Up @@ -215,11 +218,6 @@ func (c *correct) correct(ctx context.Context) (err error) {
log.Info("bbolt all batch finished")
}

// Aggregate errors for job status
if err != nil {
jobErrs = append(jobErrs, err)
}

log.Infof("correction finished for agent %s", addr)
return err

Expand Down

0 comments on commit 94d5157

Please sign in to comment.