Skip to content

fix(scraper): emit JSON errors from run under --json / --pretty#18

Open
danishashko wants to merge 1 commit into
brightdata:mainfrom
danishashko:fix/run-json-errors
Open

fix(scraper): emit JSON errors from run under --json / --pretty#18
danishashko wants to merge 1 commit into
brightdata:mainfrom
danishashko:fix/run-json-errors

Conversation

@danishashko

Copy link
Copy Markdown

Problem

A failed brightdata scraper run printed a plain-text error line to stderr even when --json / --pretty was set. An agent reading stdout (where the data would be) got nothing it could JSON.parse, so a failure was indistinguishable from empty output.

Repro: brightdata scraper run c_doesnotexist https://example.com --json → plain text on stderr, no JSON.

Fix

Route every run / batch / --sync error exit through one helper (run_fail):

  • Under --json / --pretty: write {"error": "..."} to stdout and exit 1, so the error is parseable from the same stream as success output.
  • Without those flags: unchanged — the shared red error line on stderr, exit 1.

Tests

  • New format_run_error unit tests (compact JSON, pretty JSON, Error:-prefix stripping, and the non-machine passthrough).
  • Updated the two run tests whose error path now goes through the shared helper.

Verified: tsc clean, full suite passes with no new failures, and the built binary returns valid parseable JSON ({"error":"..."}, exit 1) for run --json against a bad collector while the human path is unchanged.

A failed `scraper run` printed a plain-text error line to stderr even when
--json / --pretty was set, so an agent parsing stdout got nothing it could
JSON.parse. Route every run / batch / sync error path through one helper: under
--json / --pretty it writes {"error": "..."} to stdout and exits 1; without
those flags the behaviour is unchanged (the shared red error line on stderr).
Adds format_run_error unit tests and updates the two run tests whose error
path changed.
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.

1 participant