From b03f33d23c208a4edccb9d79bdb2e093e6a9ff79 Mon Sep 17 00:00:00 2001 From: Rudrani Mukherjee Date: Wed, 27 May 2026 10:12:12 +0530 Subject: [PATCH] docs: add Google-style docstrings to errors.py classes --- utils/errors.py | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/utils/errors.py b/utils/errors.py index 71a231c..90d2974 100644 --- a/utils/errors.py +++ b/utils/errors.py @@ -2,18 +2,38 @@ class AgentError(Exception): + """Base exception class for agent-related errors. + + Attributes: + message: Human-readable error description. + details: Additional error context as key-value pairs. + cause: Original exception that caused this error. + """ + def __init__( self, message: str, details: dict[str, Any] | None = None, cause: Exception | None = None, ) -> None: + """Initialize AgentError. + + Args: + message: Human-readable error description. + details: Additional error context as key-value pairs. + cause: Original exception that caused this error. + """ super().__init__(message) self.message = message self.details = details or {} self.cause = cause def __str__(self) -> str: + """Return string representation of the error. + + Returns: + Formatted error string with details and cause. + """ base = self.message if self.details: detail_str = ", ".join(f"{k}={v}" for k, v in self.details.items()) @@ -23,6 +43,12 @@ def __str__(self) -> str: return base def to_dict(self) -> dict[str, Any]: + """Convert error to dictionary representation. + + Returns: + Dictionary containing error type, message, + details and cause. + """ return { "type": self.__class__.__name__, "message": self.message, @@ -32,6 +58,13 @@ def to_dict(self) -> dict[str, Any]: class ConfigError(AgentError): + """Exception raised for configuration-related errors. + + Attributes: + config_key: The configuration key that caused the error. + config_file: The configuration file that caused the error. + """ + def __init__( self, message: str, @@ -39,6 +72,14 @@ def __init__( config_file: str | None = None, **kwargs: Any, ) -> None: + """Initialize ConfigError. + + Args: + message: Human-readable error description. + config_key: Configuration key that caused the error. + config_file: Configuration file that caused the error. + **kwargs: Additional keyword arguments passed to AgentError. + """ details = kwargs.pop("details", {}) or {} if config_key: details["config_key"] = config_key @@ -46,4 +87,4 @@ def __init__( details["config_file"] = config_file super().__init__(message, details=details, **kwargs) self.config_key = config_key - self.config_file = config_file + self.config_file = config_file \ No newline at end of file