← Back to Pull requests

v2.6.0: structured errors — translate non-2xx at the engine #56

Merged
karaposu merged 18 files (785 lines) on Nov 17, 2026 14:33 UTC
View on GitHub
karaposu karaposu commented on Aug 27, 2026 12:59 UTC
Author

Makes SDK failures machine-readable. Today AsyncEngine converts only HTTP 401 and 403 into exceptions and hands every other non-2xx back as an ordinary response, so each subsystem improvises its own answer and six of the seven exception types carry nothing but a prose message.

Two failures this fixes

A rate-limited request surfaced as a JSON parse error. /datasets/filter answers 429 with the bare string too_many_parallel_jobs under a non-JSON content type, and datasets/base.py called response.json() before checking the status. The user saw an aiohttp content-type error, never "you are rate limited".

A token expiring mid-poll was reported as "Job failed with status: error". DatasetAPIClient.get_status collapsed every non-200 into the string "error", discarding the status code unread — so an authentication problem was blamed on the user's scrape.

What changed

  • Classification happens once, at the single point every request already passes through: 429 → new RateLimitError (with retry_after parsed from the header), other 4xx/5xx → APIError. Bodies are read as text first, so a non-JSON error degrades to a readable message instead of a parse exception.

  • Exceptions carry data: status_code, url, method, retry_after, retryable, and raw (bounded to 4 KB).

  • Results carry it too. ScrapeResult/CrawlResult gained cause, populated wherever an exception is converted into a result — without this the structure was discarded at poll_until_ready, so it never reached scraper callers at all:

  •   result = await client.scrape.x.posts(url)
      if not result.success and isinstance(result.cause, RateLimitError):
          await asyncio.sleep(result.cause.retry_after or 60)
      

  • Retry is now opt-in. retry_with_backoff no longer retries by exception type. An error with no status code is raised locally — sometimes after the server accepted the work — so repeating it could create a duplicate billed job; those are never retried. Explicit 5xx still is. 429 never is, since those responses consume quota and retrying extends the lockout.
  • Deliberately preserved

  • HTTP 202 passes through untouched. It means success for scraper_studio.trigger_immediate, and elsewhere drives the DataNotReadyError → poll_until_ready recovery — the only working recovery path in the SDK. Covered by regression tests.

  • crawler.crawl() still returns CrawlResult on HTTP errors, and the unlocker's async get_status still returns a status string for its poll loop — both would otherwise have started raising.

  • except DatasetError still catches dataset failures: the datasets layer re-types engine errors, letting RateLimitError through as the more specific type.

  • The TimeoutError-before-OSError ordering and the SSL guidance messages are unchanged.
  • Notes for review

  • Error message text changes — messages are shorter and uniform, with detail on attributes. Code matching on message text should use status_code instead. A bounded 200-char body excerpt is appended so a bare print(exc) stays useful.

  • DatasetError now subclasses BrightDataError (still catchable as before). RateLimitError and DataNotReadyError are exported from brightdata top level.

  • Known limit: this is status-based, so it cannot see HTTP 200 responses carrying an error in the body (SERP's inner envelope, Web Unlocker error content). Those remain string-shaped.
  • Tests: 321 → 365. Version → 2.6.0.

    Diff: 785 lines (+734 / -51) across 18 files Reviewer: tjkilgore93-stack Review duration: 118173m
    All Vouch review confidence checks passed
    Residual risk 0.37 = Change Risk (0.71) × (1 − Review Confidence (0.48)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.71 · 785 lines diff across 18 files
    0.71
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.00 · 1 substantive comment(s)
    0.00
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    48%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.399
    Shallow Review Depth shallow_review_depth
    0.350
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    2 items
    tjkilgore93-stack tjkilgore93-stack approved these changes on Sep 08, 2026 08:21 UTC
    Approved Reviewer

    Approved these changes.

    Assignees
    karaposu karaposu
    Labels
    risk: medium confidence: 48.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 71.4% (HIGH) · Higher = larger blast radius
    71.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 48.5% · Lower = rushed or shallow review
    48.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 36.8% · Moderate risk
    36.8%