refactor: remove redundant try-catch-log-reraise patterns

Remove unnecessary exception handling that only logs and re-raises exceptions.
The outer layers already handle and log exceptions appropriately, so these
intermediate catch blocks just add noise to logs and complicate the code.

- Remove try-catch from HITLReviewHelper._handle_review_request
- Remove try-catch from HumanInTheLoopBlock.run
- Let exceptions bubble up naturally to be handled at appropriate levels
This commit is contained in:
Zamil Majdy
2026-01-08 18:10:56 -06:00
parent d99cb46edd
commit 15eb5ad26f
2 changed files with 26 additions and 42 deletions

View File

@@ -89,38 +89,26 @@ class HITLReviewHelper:
)
return None
try:
result = await HITLReviewHelper.get_or_create_human_review(
user_id=user_id,
node_exec_id=node_exec_id,
graph_exec_id=graph_exec_id,
graph_id=graph_id,
graph_version=graph_version,
input_data=input_data,
message=f"Review required for {block_name} execution",
editable=editable,
)
except Exception as e:
logger.error(
f"Error creating review for {block_name} node {node_exec_id}: {str(e)}"
)
raise
result = await HITLReviewHelper.get_or_create_human_review(
user_id=user_id,
node_exec_id=node_exec_id,
graph_exec_id=graph_exec_id,
graph_id=graph_id,
graph_version=graph_version,
input_data=input_data,
message=f"Review required for {block_name} execution",
editable=editable,
)
if result is None:
logger.info(
f"Block {block_name} pausing execution for node {node_exec_id} - awaiting human review"
)
try:
await HITLReviewHelper.update_node_execution_status(
exec_id=node_exec_id,
status=ExecutionStatus.REVIEW,
)
return None # Signal that execution should pause
except Exception as e:
logger.error(
f"Failed to update node status for block {block_name} {node_exec_id}: {str(e)}"
)
raise
await HITLReviewHelper.update_node_execution_status(
exec_id=node_exec_id,
status=ExecutionStatus.REVIEW,
)
return None # Signal that execution should pause
# Mark review as processed if not already done
if not result.processed:

View File

@@ -112,21 +112,17 @@ class HumanInTheLoopBlock(Block):
yield "review_message", "Auto-approved (safe mode disabled)"
return
try:
decision = await self.handle_review_decision(
input_data=input_data.data,
user_id=user_id,
node_exec_id=node_exec_id,
graph_exec_id=graph_exec_id,
graph_id=graph_id,
graph_version=graph_version,
execution_context=execution_context,
block_name=self.name,
editable=input_data.editable,
)
except Exception as e:
logger.error(f"Error in HITL block for node {node_exec_id}: {str(e)}")
raise
decision = await self.handle_review_decision(
input_data=input_data.data,
user_id=user_id,
node_exec_id=node_exec_id,
graph_exec_id=graph_exec_id,
graph_id=graph_id,
graph_version=graph_version,
execution_context=execution_context,
block_name=self.name,
editable=input_data.editable,
)
if decision is None:
# Execution is paused, the helper already handled status updates