fix(scraper): emit JSON errors from run under --json / --pretty#18
Open
danishashko wants to merge 1 commit into
Open
fix(scraper): emit JSON errors from run under --json / --pretty#18danishashko wants to merge 1 commit into
danishashko wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A failed
brightdata scraper runprinted a plain-text error line to stderr even when--json/--prettywas set. An agent reading stdout (where the data would be) got nothing it couldJSON.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/--syncerror exit through one helper (run_fail):--json/--pretty: write{"error": "..."}to stdout and exit 1, so the error is parseable from the same stream as success output.Tests
format_run_errorunit tests (compact JSON, pretty JSON,Error:-prefix stripping, and the non-machine passthrough).runtests whose error path now goes through the shared helper.Verified:
tscclean, full suite passes with no new failures, and the built binary returns valid parseable JSON ({"error":"..."}, exit 1) forrun --jsonagainst a bad collector while the human path is unchanged.