Implement error handling with clear intent and proper propagation. Follow these principles: 1. Use structured try/catch blocks with specific error types
Implement error handling with clear intent and proper propagation. Follow these principles:
Example of proper error handling structure:
try:
if self.max_execution_time is not None:
if not isinstance(self.max_execution_time, int) or self.max_execution_time <= 0:
raise ValueError("Max Execution time must be a positive integer greater than zero")
result = self._execute_with_timeout(task_prompt, task, self.max_execution_time)
else:
result = self._execute_without_timeout(task_prompt, task)
except TimeoutError as e:
error = f"Task '{task.description}' execution timed out after {self.max_execution_time} seconds. Consider increasing max_execution_time or optimizing the task."
crewai_event_bus.emit(
self,
event=AgentExecutionErrorEvent(
agent=self,
task=task,
error=error
)
)
raise TimeoutError(error)
This pattern ensures:
Enter the URL of a public GitHub repository