Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: Implement structured exception hierarchy #111

Open
mathysgrapotte opened this issue Feb 19, 2025 · 1 comment
Open

change: Implement structured exception hierarchy #111

mathysgrapotte opened this issue Feb 19, 2025 · 1 comment

Comments

@mathysgrapotte
Copy link
Owner

Is your change request related to a problem? Please describe.

Current error handling uses generic exceptions without context, making debugging difficult in pipeline executions.

Describe the solution you'd like

  1. Create stimulus/exceptions.py with base StimulusError and component-specific exceptions
  2. Implement context-rich error formatting with component details
  3. Update core classes to raise appropriate exception types
@mathysgrapotte
Copy link
Owner Author

example implementation for context :

from typing import Optional, Dict, Any

class StimulusError(Exception):
    """Base exception with context-aware formatting"""
    
    def __init__(self, msg: str, context: Optional[Dict[str, Any]] = None):
        super().__init__(msg)
        self.context = context or {}
        
    def add_context(self, **additional_context: Any) -> "StimulusError":
        """Chainable context builder"""
        self.context.update(additional_context)
        return self
        
    def __str__(self) -> str:
        base_msg = super().__str__()
        if self.context:
            ctx_str = " | ".join(f"{k}={v}" for k,v in self.context.items())
            return f"{base_msg} [{ctx_str}]"
        return base_msg

class LoaderConfigError(StimulusError):
    """Raised when loader configuration is invalid"""
    
# Usage in loader class
class DataLoader:
    def __init__(self, config: dict):
        if "columns" not in config:
            raise LoaderConfigError("Missing columns definition").add_context(
                config_keys=list(config.keys()),
                loader_type=self.__class__.__name__
            )

@mathysgrapotte mathysgrapotte moved this to Todo - depend on other issues in Stimulus v1.0 Feb 19, 2025
@mathysgrapotte mathysgrapotte moved this from Todo - depend on other issues to Todo in Stimulus v1.0 Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant