Skip to content

Commit

Permalink
make parallel run fail instead of returning none
Browse files Browse the repository at this point in the history
  • Loading branch information
tjwald committed Jan 22, 2025
1 parent 2d6beff commit 33c362d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions checkov/common/parallelizer/parallel_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
_T = TypeVar("_T")


class ParallelRunException(Exception):
def __init__(self, internal_exception: Exception) -> None:
self.internal_exception = internal_exception
super().__init__("Parallel run failed", internal_exception)


class ParallelRunner:
def __init__(
self, workers_number: int | None = None,
Expand Down Expand Up @@ -72,12 +78,12 @@ def func_wrapper(original_func: Callable[[Any], _T], items_group: List[Any], con
result = original_func(*item)
else:
result = original_func(item)
except Exception:
except Exception as e:
logging.error(
f"Failed to invoke function {func.__code__.co_filename.replace('.py', '')}.{func.__name__} with {item}",
exc_info=True,
)
result = None
result = ParallelRunException(e)

connection.send(result)
connection.close()
Expand All @@ -97,7 +103,12 @@ def func_wrapper(original_func: Callable[[Any], _T], items_group: List[Any], con
for _, parent_conn, group_len in processes:
for _ in range(group_len):
try:
yield parent_conn.recv()
v = parent_conn.recv()

if isinstance(v, ParallelRunException):
raise v.internal_exception

yield v
except EOFError:
pass

Expand Down

0 comments on commit 33c362d

Please sign in to comment.