@@ -273,7 +273,7 @@ func (l *Loader[KeyT, ValueT]) startBatch(ctx context.Context) {
273
273
}
274
274
}
275
275
276
- batch .results , batch .errors = l .fetch (batch .firstContext , batch .keys )
276
+ batch .results , batch .errors = l .safeFetch (batch .firstContext , batch .keys )
277
277
278
278
if l .tracer != nil {
279
279
for _ , span := range spans {
@@ -286,6 +286,16 @@ func (l *Loader[KeyT, ValueT]) startBatch(ctx context.Context) {
286
286
}
287
287
}
288
288
289
+ func (l * Loader [KeyT , ValueT ]) safeFetch (ctx context.Context , keys []KeyT ) (values []ValueT , errs []error ) {
290
+ defer func () {
291
+ panicValue := recover ()
292
+ if panicValue != nil {
293
+ errs = []error {fmt .Errorf ("panic during fetch: %v" , panicValue )}
294
+ }
295
+ }()
296
+ return l .fetch (ctx , keys )
297
+ }
298
+
289
299
// addKeyToBatch will return the location of the key in the batch, if its not found
290
300
// it will add the key to the batch
291
301
func (l * Loader [KeyT , ValueT ]) addKeyToBatch (b * loaderBatch [KeyT , ValueT ], key KeyT ) int {
@@ -305,7 +315,7 @@ func (l *Loader[KeyT, ValueT]) addKeyToBatch(b *loaderBatch[KeyT, ValueT], key K
305
315
}
306
316
}
307
317
308
- b .results , b .errors = l .fetch (b .firstContext , b .keys )
318
+ b .results , b .errors = l .safeFetch (b .firstContext , b .keys )
309
319
310
320
if l .tracer != nil {
311
321
for _ , span := range spans {
0 commit comments