Alerts Exceptions¶
Exception hierarchy for the alerts subsystem.
Exception Hierarchy¶
KstlibError
└── AlertError
├── AlertConfigurationError
├── AlertDeliveryError
└── AlertThrottledError
Base Exception¶
Configuration Errors¶
- exception kstlib.alerts.exceptions.AlertConfigurationError[source]¶
Bases:
AlertErrorRaised when alert configuration is invalid or incomplete.
Raised when alert configuration is invalid:
Invalid webhook URL format
Missing required parameters
Invalid channel configuration
Delivery Errors¶
- exception kstlib.alerts.exceptions.AlertDeliveryError(message, *, channel, retryable=False)[source]¶
Bases:
AlertErrorRaised when an alert cannot be delivered to a channel.
- channel¶
The name of the channel that failed.
- retryable¶
Whether the error is potentially recoverable with retry.
Examples
>>> err = AlertDeliveryError("Connection failed", channel="slack", retryable=True) >>> err.channel 'slack' >>> err.retryable True
Raised when alert delivery fails:
Network errors
HTTP errors (4xx, 5xx)
Timeout errors
The retryable attribute indicates if the operation can be retried.
Throttle Errors¶
- exception kstlib.alerts.exceptions.AlertThrottledError(message, *, retry_after)[source]¶
Bases:
AlertErrorRaised when an alert is throttled due to rate limiting.
- retry_after¶
Seconds until the next alert can be sent.
Examples
>>> err = AlertThrottledError("Rate limit exceeded", retry_after=30.0) >>> err.retry_after 30.0
Raised when alert is rate-limited:
Rate limit exceeded
Timeout waiting for token
The retry_after attribute indicates seconds until next attempt.
Usage Examples¶
from kstlib.alerts.exceptions import (
AlertError,
AlertConfigurationError,
AlertDeliveryError,
AlertThrottledError,
)
try:
await channel.send(alert)
except AlertThrottledError as e:
log.warning(f"Throttled, retry after {e.retry_after}s")
except AlertDeliveryError as e:
if e.retryable:
await retry_later(alert)
else:
log.error(f"Permanent failure: {e}")
except AlertConfigurationError as e:
log.error(f"Config error: {e}")
except AlertError as e:
log.error(f"Alert error: {e}")