Skip to content

Name the day and the reason when an async Binance download fails - #48

Merged
stefan-jansen merged 1 commit into
mainfrom
fix/binance-async-failure-reasons
Sep 8, 2026
Merged

Name the day and the reason when an async Binance download fails#48
stefan-jansen merged 1 commit into
mainfrom
fix/binance-async-failure-reasons

Conversation

@stefan-jansen

Copy link
Copy Markdown
Contributor

An async Binance download failure said nothing about itself.

The async daily path returned a bare exception from fetch_one and logged f"Failed to download: {result}". str(exc) is empty for an exception raised with no arguments, so the line rendered with no subject and no reason:

2026-09-05 20:06:29 [warning  ] Failed to download:
2026-09-05 20:06:29 [warning  ] Failed to download:
... 569 times

That is from run 33988501549 of the book repository's Reader install job. Five of nineteen Binance perpetual symbols were unavailable upstream; six of the seven free datasets downloaded fine. Reading only the log, it was indistinguishable from every source failing, and diagnosing it meant going to the raw job-log REST endpoint and counting [OK]/[FAIL] lines in the summary block. The premium-index monthly path had the same shape at debug level (Monthly fetch failed for (2021, 1):).

fetch_one now carries the date out alongside the failure, and both sites log structured fields through a shared _failure_reason, which falls back to the exception's type when it carries no message of its own:

Failed to download  date=2024-01-02 reason=TimeoutError symbol=BTCUSDT

Four tests in tests/test_binance_public_edge_cases.py: the three _failure_reason branches (argument-less, with a message, whitespace-only), and one that drives _fetch_daily_data_async with an argument-less TimeoutError and asserts both that the date, symbol and reason are present and that the old subject-less Failed to download: is not.

Verification

uv run pytest tests/ -q: 3,623 passed, 280 deselected. ruff check, ruff format --check and ty check clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WfX5GbAHc5EVwdUnRSoUPT

The async daily path returned a bare exception and logged `f"Failed to download:
{result}"`. `str(exc)` is empty for an exception raised with no arguments, so the
line rendered with no subject and no reason at all. Run 33988501549 of the book
repository's reader-install job emitted 569 of them, which is what turned a
five-symbol Binance outage into a whole seven-dataset job failing with nothing to
read. The premium-index monthly path had the same shape at debug level.

`fetch_one` now carries the date out with the failure, and both sites log
structured fields through `_failure_reason`, which falls back to the exception's
type when it carries no message:

  Failed to download  date=2024-01-02 reason=TimeoutError symbol=BTCUSDT

Four tests, including one that drives the async daily path with an argument-less
`TimeoutError` and asserts the old subject-less line is not what comes out.

`uv run pytest tests/ -q`: 3,623 passed, 280 deselected. ruff and ty clean.
Copilot AI lite review requested due to automatic review settings September 8, 2026 21:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@stefan-jansen
stefan-jansen merged commit a5cade3 into main Sep 8, 2026
22 checks passed
@stefan-jansen
stefan-jansen deleted the fix/binance-async-failure-reasons branch September 8, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants