Coverage for src/polars_yahoo/exceptions.py: 100%
23 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-17 15:16 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-17 15:16 +0000
1"""Exceptions raised by polars-yahoo."""
3from __future__ import annotations
6class YahooError(Exception):
7 """Base class for every error this package raises."""
10class TickerNotFoundError(YahooError):
11 """Yahoo has no data for the symbol (unknown or delisted)."""
13 def __init__(self, ticker: str, reason: str | None = None) -> None:
14 """Record the ticker and Yahoo's own explanation, if it gave one."""
15 self.ticker = ticker
16 self.reason = reason
17 super().__init__(f"{ticker}: {reason or 'no data found'}")
20class RateLimitError(YahooError):
21 """Yahoo kept answering HTTP 429 after all retries."""
23 def __init__(self, ticker: str, retries: int) -> None:
24 """Record the ticker and how many retries were spent."""
25 self.ticker = ticker
26 self.retries = retries
27 super().__init__(f"{ticker}: Yahoo rate limit (HTTP 429) persisted after {retries} retries")
30class NetworkError(YahooError):
31 """The request never got an HTTP response (timeout, DNS or connection failure)."""
33 def __init__(self, ticker: str, reason: str) -> None:
34 """Record the ticker and the transport error's message."""
35 self.ticker = ticker
36 self.reason = reason
37 super().__init__(f"{ticker}: network error: {reason}")
40class ResponseError(YahooError):
41 """Yahoo answered with something other than usable chart data."""
43 def __init__(self, ticker: str, status: int, reason: str) -> None:
44 """Record the ticker, the HTTP status and what was wrong with the response."""
45 self.ticker = ticker
46 self.status = status
47 self.reason = reason
48 super().__init__(f"{ticker}: HTTP {status}: {reason}")