Skip to content

Fix CLI exit codes and degraded scrape response handling#40

Merged
paulius-krutkis-dcd merged 4 commits into
mainfrom
fix-cli-exit-codes-and-scrape-failures
Jun 26, 2026
Merged

Fix CLI exit codes and degraded scrape response handling#40
paulius-krutkis-dcd merged 4 commits into
mainfrom
fix-cli-exit-codes-and-scrape-failures

Conversation

@paulius-krutkis-dcd

@paulius-krutkis-dcd paulius-krutkis-dcd commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Map API validation errors (400/422) to exit code 4 so scripts do not retry permanent input failures as network errors
  • Detect API-level scrape failures (status: "failed" envelopes, HTTP errors with no usable body) and exit 7 without writing to stdout
  • When an HTTP error still returns usable content, warn on stderr but emit the body so pipelines can use partial results

Test plan

  • Trigger a validation error (e.g. bad target input) and confirm exit code 4
  • Trigger a scrape that returns a status: "failed" envelope and confirm exit 7 with no stdout output
  • Trigger a scrape that returns HTTP 4xx with a body and confirm stdout has content, stderr shows a warning, exit 0
  • Run pnpm test — all tests pass

Map plain 400/422 API errors to the documented VALIDATION exit code (4)
instead of NETWORK (7), so scripts can distinguish permanent input errors
from transient network failures.

Detect server-side scrape failures (failed content envelopes and HTTP
error statuses) and exit non-zero with the API message on stderr, instead
of printing the failure body to stdout and exiting 0.
Introduced a new function, detectDegradedStatus, to identify HTTP errors that still return usable content. Updated the detectScrapeFailure function to utilize this new logic. Enhanced writeScrapeResponse to log warnings for degraded statuses. Added corresponding tests to ensure correct behavior for both functions, including scenarios where HTTP errors return valid content.
@paulius-krutkis-dcd paulius-krutkis-dcd changed the title Fix CLI exit codes for validation and API-level scrape failures Fix CLI exit codes and degraded scrape response handling Jun 26, 2026
Target 5xx responses come back as a top-level { status: "failed" }
envelope with no results array. detectScrapeFailure now inspects the
response itself for that envelope before iterating, so the failure
surfaces as a ScrapeFailedError (exit 7) with the API's guidance
instead of crashing with "results is not iterable".

Both detectScrapeFailure and detectDegradedStatus now read results
through a guard, so a missing or non-array results never throws.
Pin vite to ^7.3.5 and esbuild to ^0.28.1 via pnpm overrides to clear
the Dependabot advisories (vite server.fs.deny bypass and launch-editor
NTLM disclosure, esbuild dev-server file read). Both are transitive
dev-only deps via vitest and never ship in the CLI bundle.
@paulius-krutkis-dcd paulius-krutkis-dcd merged commit ee4fc2c into main Jun 26, 2026
1 check passed
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.

3 participants