Skip to content

Commit 1a03a33

Browse files
Fix exception handling issues
- Add 'from e' to exception raises for proper exception chaining (B904) - Remove return from finally block to prevent exception silencing (B012)
1 parent ad13443 commit 1a03a33

File tree

3 files changed

+15
-17
lines changed
  • examples/tutorials/10_agentic/00_base/080_batch_events/project
  • src/agentex

3 files changed

+15
-17
lines changed

examples/tutorials/10_agentic/00_base/080_batch_events/project/acp.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,17 @@ async def handle_task_event_send(params: SendEventParams) -> None:
199199
logger.error(f"❌ Task cancelled: {e}")
200200
reset_to_ready = False
201201
finally:
202-
if not reset_to_ready:
203-
return
204-
205-
# Always set status back to READY when done processing
206-
try:
207-
await adk.agent_task_tracker.update(
208-
tracker_id=tracker.id,
209-
status=Status.READY.value,
210-
status_reason="Completed event processing - ready for new events"
211-
)
212-
logger.info(f"🟢 Set status back to READY - agent available for new events")
213-
except Exception as e:
214-
logger.error(f"❌ Error setting status back to READY: {e}")
202+
if reset_to_ready:
203+
# Always set status back to READY when done processing
204+
try:
205+
await adk.agent_task_tracker.update(
206+
tracker_id=tracker.id,
207+
status=Status.READY.value,
208+
status_reason="Completed event processing - ready for new events"
209+
)
210+
logger.info(f"🟢 Set status back to READY - agent available for new events")
211+
except Exception as e:
212+
logger.error(f"❌ Error setting status back to READY: {e}")
215213

216214

217215
@acp.on_task_cancel

src/agentex/lib/cli/commands/agents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ def deploy(
293293
except EnvironmentsValidationError as e:
294294
error_msg = generate_helpful_error_message(e, "Environment validation failed")
295295
console.print(f"[red]Configuration Error:[/red]\n{error_msg}")
296-
raise typer.Exit(1)
296+
raise typer.Exit(1) from e
297297
except Exception as e:
298298
console.print(f"[red]Error:[/red] Failed to validate configuration: {e}")
299-
raise typer.Exit(1)
299+
raise typer.Exit(1) from e
300300

301301
# Load manifest for credential validation
302302
manifest_obj = AgentManifest.from_yaml(str(manifest_path))

src/agentex/resources/agents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,8 +1081,8 @@ async def send_message_stream(
10811081
except json.JSONDecodeError:
10821082
# Skip invalid JSON lines
10831083
continue
1084-
except ValidationError:
1085-
raise ValueError(f"Invalid SendMessageStreamResponse returned: {line}")
1084+
except ValidationError as e:
1085+
raise ValueError(f"Invalid SendMessageStreamResponse returned: {line}") from e
10861086

10871087
async def send_event(
10881088
self,

0 commit comments

Comments
 (0)