refactor: replace generic Exception handling with specific exceptions in agents.py
This commit is contained in:
@@ -517,7 +517,7 @@ async def create_agent(
|
|||||||
except OpenClawGatewayError as exc:
|
except OpenClawGatewayError as exc:
|
||||||
_record_instruction_failure(session, agent, str(exc), "provision")
|
_record_instruction_failure(session, agent, str(exc), "provision")
|
||||||
await session.commit()
|
await session.commit()
|
||||||
except Exception as exc: # pragma: no cover - unexpected provisioning errors
|
except (OSError, RuntimeError, ValueError) as exc: # pragma: no cover
|
||||||
_record_instruction_failure(session, agent, str(exc), "provision")
|
_record_instruction_failure(session, agent, str(exc), "provision")
|
||||||
await session.commit()
|
await session.commit()
|
||||||
main_session_keys = await _get_gateway_main_session_keys(session)
|
main_session_keys = await _get_gateway_main_session_keys(session)
|
||||||
@@ -708,7 +708,7 @@ async def update_agent(
|
|||||||
status_code=status.HTTP_502_BAD_GATEWAY,
|
status_code=status.HTTP_502_BAD_GATEWAY,
|
||||||
detail=f"Gateway update failed: {exc}",
|
detail=f"Gateway update failed: {exc}",
|
||||||
) from exc
|
) from exc
|
||||||
except Exception as exc: # pragma: no cover - unexpected provisioning errors
|
except (OSError, RuntimeError, ValueError) as exc: # pragma: no cover
|
||||||
_record_instruction_failure(session, agent, str(exc), "update")
|
_record_instruction_failure(session, agent, str(exc), "update")
|
||||||
await session.commit()
|
await session.commit()
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
@@ -838,7 +838,7 @@ async def heartbeat_or_create_agent(
|
|||||||
except OpenClawGatewayError as exc:
|
except OpenClawGatewayError as exc:
|
||||||
_record_instruction_failure(session, agent, str(exc), "provision")
|
_record_instruction_failure(session, agent, str(exc), "provision")
|
||||||
await session.commit()
|
await session.commit()
|
||||||
except Exception as exc: # pragma: no cover - unexpected provisioning errors
|
except (OSError, RuntimeError, ValueError) as exc: # pragma: no cover
|
||||||
_record_instruction_failure(session, agent, str(exc), "provision")
|
_record_instruction_failure(session, agent, str(exc), "provision")
|
||||||
await session.commit()
|
await session.commit()
|
||||||
else:
|
else:
|
||||||
@@ -890,7 +890,7 @@ async def heartbeat_or_create_agent(
|
|||||||
except OpenClawGatewayError as exc:
|
except OpenClawGatewayError as exc:
|
||||||
_record_instruction_failure(session, agent, str(exc), "provision")
|
_record_instruction_failure(session, agent, str(exc), "provision")
|
||||||
await session.commit()
|
await session.commit()
|
||||||
except Exception as exc: # pragma: no cover - unexpected provisioning errors
|
except (OSError, RuntimeError, ValueError) as exc: # pragma: no cover
|
||||||
_record_instruction_failure(session, agent, str(exc), "provision")
|
_record_instruction_failure(session, agent, str(exc), "provision")
|
||||||
await session.commit()
|
await session.commit()
|
||||||
elif actor.actor_type == "agent" and actor.agent and actor.agent.id != agent.id:
|
elif actor.actor_type == "agent" and actor.agent and actor.agent.id != agent.id:
|
||||||
@@ -957,7 +957,7 @@ async def delete_agent(
|
|||||||
status_code=status.HTTP_502_BAD_GATEWAY,
|
status_code=status.HTTP_502_BAD_GATEWAY,
|
||||||
detail=f"Gateway cleanup failed: {exc}",
|
detail=f"Gateway cleanup failed: {exc}",
|
||||||
) from exc
|
) from exc
|
||||||
except Exception as exc: # pragma: no cover - unexpected cleanup errors
|
except (OSError, RuntimeError, ValueError) as exc: # pragma: no cover
|
||||||
_record_instruction_failure(session, agent, str(exc), "delete")
|
_record_instruction_failure(session, agent, str(exc), "delete")
|
||||||
await session.commit()
|
await session.commit()
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
@@ -1022,7 +1022,7 @@ async def delete_agent(
|
|||||||
config=client_config,
|
config=client_config,
|
||||||
deliver=False,
|
deliver=False,
|
||||||
)
|
)
|
||||||
except Exception:
|
except (OSError, OpenClawGatewayError, ValueError):
|
||||||
# Cleanup request is best-effort; deletion already completed.
|
# Cleanup request is best-effort; deletion already completed.
|
||||||
pass
|
pass
|
||||||
return OkResponse()
|
return OkResponse()
|
||||||
|
|||||||
Reference in New Issue
Block a user