Skip to content

v2: raise exceptions instead of returning MarketDataClientErrorResult #20

@MarketDataApp

Description

@MarketDataApp

Summary

The v1.x SDK returns MarketDataClientErrorResult from every endpoint method instead of raising exceptions. This violates SDK Requirements §6.4, which requires idiomatic Python error handling (raise exceptions). Tracking for v2.0 because every existing caller depends on the current return type.

The requirements doc names this explicitly:

*** Python SDK Technical Debt:** The current Python SDK (v1.x) returns MarketDataClientErrorResult instead of raising exceptions. This is non-idiomatic and will be fixed in v2.0.

Current behavior

handle_exceptions in src/marketdata/sdk_error.py wraps every endpoint method and converts any exception into a MarketDataClientErrorResult:

result = client.stocks.quotes("AAPL")
if isinstance(result, MarketDataClientErrorResult):
    print(result.support_info)

v2 target

try:
    quotes = client.stocks.quotes("AAPL")
except BaseMarketdataException as e:
    print(e.support_info)

In-scope changes

  1. Remove the handle_exceptions decorator (src/marketdata/sdk_error.py). Endpoint methods raise exceptions naturally.
  2. Remove MarketDataClientErrorResult from the public API and from marketdata.__init__ re-exports.
  3. Move the support_info formatted string from MarketDataClientErrorResult onto BaseMarketdataException so it's accessible via error.support_info (§6.3).
  4. Ensure every exception class carries the §6.2 support-context fields (request_id, request_url, status_code, timestamp, message, exception_type). Currently only MarketdataHttpError subclasses have the HTTP fields; RateLimitError, MinMaxDateValidationError, KeywordOnlyArgumentError, InvalidStatusDataError extend BaseMarketdataException and lack them.
  5. Update every endpoint method in src/marketdata/resources/**/*.py to drop MarketDataClientErrorResult from return type annotations and the from ... import MarketDataClientErrorResult lines.
  6. Update tests to use pytest.raises instead of isinstance checks.
  7. Update README and docs with the new error-handling pattern.

Out of scope (separate v2 issues to follow)

  • Expanding the exception taxonomy to add AuthenticationError, BadRequestError, NotFoundError, ServerError, NetworkError, ParseError (§6.1).
  • Status-code → exception mapping (§9.1: 401 fail-fast, 404 returns no-data response, etc.).
  • Other v2 breaking changes (e.g. fixed/non-configurable timeout per §10).

Why this requires v2

Every caller currently does if isinstance(result, MarketDataClientErrorResult): .... Removing the type from the public API and changing return signatures to raise instead breaks all such callers — major version bump required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions