Skip to content

Commit

Permalink
Custom BatchRequestError handling in pipeline.request_batch
Browse files Browse the repository at this point in the history
We can filter out some more of the excess error traceback that isn't helpful to the readers.
  • Loading branch information
pattonw committed Jan 2, 2024
1 parent d55c976 commit 00543bf
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions gunpowder/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import logging
from gunpowder.nodes import BatchProvider
from gunpowder.nodes.batch_provider import BatchRequestError

import logging
import traceback

logger = logging.getLogger(__name__)

Expand All @@ -21,13 +24,19 @@ def __str__(self):


class PipelineRequestError(Exception):
def __init__(self, pipeline, request):
def __init__(self, pipeline, request, original_traceback=None):
self.pipeline = pipeline
self.request = request
self.original_traceback = original_traceback

def __str__(self):
return (
"Exception in pipeline:\n"
(
("".join(self.original_traceback) )
if self.original_traceback is not None
else ""
)
+ "Exception in pipeline:\n"
f"{self.pipeline}\n"
"while trying to process request\n"
f"{self.request}"
Expand Down Expand Up @@ -123,6 +132,11 @@ def request_batch(self, request):

try:
return self.output.request_batch(request)
except BatchRequestError as e:
tb = traceback.format_exception(type(e), e, e.__traceback__)
if isinstance(e, BatchRequestError):
tb = tb[-1:]
raise PipelineRequestError(self, request, original_traceback=tb) from None
except Exception as e:
raise PipelineRequestError(self, request) from e

Expand Down

0 comments on commit 00543bf

Please sign in to comment.