Skip to content

Commit c9abb18

Browse files
committed
Add more context to error returned by Run
Add information what was the cause of the error.
1 parent e942404 commit c9abb18

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

batch.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package batch
55

66
import (
77
"context"
8+
"fmt"
89
"sync"
910
"time"
1011
)
@@ -148,7 +149,11 @@ func (p *Processor[Resource]) Run(ctx context.Context, key string, _operation fu
148149
return OperationCancelled
149150

150151
case tempBatch.incomingOperations <- operationMessage:
151-
return <-result
152+
err := <-result
153+
if err != nil {
154+
return fmt.Errorf("running batch failed for key '%s': %w", key, err)
155+
}
156+
return nil
152157

153158
case <-tempBatch.closed:
154159
}

goroutine.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package batch
55

66
import (
77
"context"
8+
"fmt"
89
"time"
910
)
1011

@@ -79,7 +80,7 @@ func (b *batch[Resource]) save(ctx context.Context) error {
7980
}()
8081

8182
if err := b.SaveResource(ctx, b.resourceKey, *b.resource); err != nil {
82-
return err
83+
return fmt.Errorf("saving resource failed: %w", err)
8384
}
8485

8586
return nil
@@ -97,7 +98,7 @@ func (b *batch[Resource]) load(ctx context.Context) error {
9798

9899
resource, err := b.LoadResource(ctx, b.resourceKey)
99100
if err != nil {
100-
return err
101+
return fmt.Errorf("loading resource failed: %w", err)
101102
}
102103

103104
b.resource = &resource

0 commit comments

Comments
 (0)