Merge 8e741a1074
into 2dc4684476
commit
5f7d537804
@ -0,0 +1,41 @@
|
|||||||
|
from enum import Enum
|
||||||
|
from typing import Dict, Optional
|
||||||
|
|
||||||
|
class ErrorSeverity(Enum):
|
||||||
|
"""Enum for error severity levels."""
|
||||||
|
LOW = "low"
|
||||||
|
MEDIUM = "medium"
|
||||||
|
HIGH = "high"
|
||||||
|
CRITICAL = "critical"
|
||||||
|
|
||||||
|
class ToolAgentError(Exception):
|
||||||
|
"""Base exception class for ToolAgent errors."""
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
message: str,
|
||||||
|
severity: ErrorSeverity = ErrorSeverity.MEDIUM,
|
||||||
|
details: Optional[Dict] = None
|
||||||
|
):
|
||||||
|
self.severity = severity
|
||||||
|
self.details = details or {}
|
||||||
|
super().__init__(message)
|
||||||
|
|
||||||
|
class ValidationError(ToolAgentError):
|
||||||
|
"""Raised when validation fails."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
class ModelNotProvidedError(ToolAgentError):
|
||||||
|
"""Raised when neither model nor llm is provided."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
class SecurityError(ToolAgentError):
|
||||||
|
"""Raised when security checks fail."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
class SchemaValidationError(ToolAgentError):
|
||||||
|
"""Raised when JSON schema validation fails."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
class ConfigurationError(ToolAgentError):
|
||||||
|
"""Raised when there's an error in configuration."""
|
||||||
|
pass
|
@ -0,0 +1,32 @@
|
|||||||
|
from swarms.agents.exceptions import (
|
||||||
|
ErrorSeverity,
|
||||||
|
ToolAgentError,
|
||||||
|
ValidationError,
|
||||||
|
ModelNotProvidedError
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_error_severity():
|
||||||
|
assert ErrorSeverity.LOW.value == "low"
|
||||||
|
assert ErrorSeverity.MEDIUM.value == "medium"
|
||||||
|
assert ErrorSeverity.HIGH.value == "high"
|
||||||
|
assert ErrorSeverity.CRITICAL.value == "critical"
|
||||||
|
|
||||||
|
def test_tool_agent_error():
|
||||||
|
error = ToolAgentError(
|
||||||
|
"Test error",
|
||||||
|
severity=ErrorSeverity.HIGH,
|
||||||
|
details={"test": "value"}
|
||||||
|
)
|
||||||
|
assert str(error) == "Test error"
|
||||||
|
assert error.severity == ErrorSeverity.HIGH
|
||||||
|
assert error.details == {"test": "value"}
|
||||||
|
|
||||||
|
def test_validation_error():
|
||||||
|
error = ValidationError("Validation failed")
|
||||||
|
assert isinstance(error, ToolAgentError)
|
||||||
|
assert str(error) == "Validation failed"
|
||||||
|
|
||||||
|
def test_model_not_provided_error():
|
||||||
|
error = ModelNotProvidedError("Model missing")
|
||||||
|
assert isinstance(error, ToolAgentError)
|
||||||
|
assert str(error) == "Model missing"
|
Loading…
Reference in new issue