fix(batch-scrape): exit 1 when a waited batch ends failed or cancelled

PC
1d ago
+101-0

Exit with status 1 when batch-scrape --wait ends in failed or cancelled, as crawl --wait already does.

Problem. handleBatchScrapeCommand never set an exit code for the final job status. With --wait (with or without --progress), a batch that finished failed or cancelled printed its JSON and exited 0, so scripts and CI pipelines treated it as a success. crawl --wait already exits 1 in the same situation.

Reproduction. Run firecrawl batch-scrape <urls> --wait against a job whose final status is failed: the process exits 0. With a mocked client returning status: 'failed' from batchScrape, process.exitCode stays undefined.

Fix. After writing the output, if --wait was used and the final status is failed or cancelled, print Error: Batch scrape <status>. to stderr and set process.exitCode = 1, mirroring crawl.ts. The JSON output is unchanged. Starting a job without --wait, reading a status by job ID, and completed are unaffected.

Test. New handleBatchScrapeCommand exit status tests in batch-scrape.test.ts cover failed and cancelled (exit 1, JSON still printed, stderr message) and confirm exit status is left alone for completed and for reading a failed job without --wait. The two failing cases fail on main and pass with the change (28/28 in the file); tsc --noEmit and prettier --check are clean.

This pull request was prepared with the assistance of an AI coding agent (Claude Code) and submitted by Alex Castillo, who is responsible for its content.


Summary by cubic

Makes batch-scrape --wait exit with status 1 when the batch ends failed or cancelled, matching crawl --wait. Previously it printed the final JSON and exited 0, so scripts and CI pipelines treated failed batches as successful.

  • Prints Error: Batch scrape <status>. to stderr and sets process.exitCode = 1.
  • JSON output and all other code paths (completed, no --wait, --cancel --wait) are unchanged.