Skip to content

Add exit code differentiation for external vs internal crawl errors#51

Merged
YusukeHirao merged 4 commits intomainfrom
claude/improve-exit-codes-mZbmV
Mar 9, 2026
Merged

Add exit code differentiation for external vs internal crawl errors#51
YusukeHirao merged 4 commits intomainfrom
claude/improve-exit-codes-mZbmV

Conversation

@YusukeHirao
Copy link
Copy Markdown
Member

@YusukeHirao YusukeHirao commented Mar 7, 2026

Summary

This PR introduces differentiated exit codes for the crawl and pipeline commands to distinguish between fatal errors (exit code 1) and non-fatal external link errors (exit code 2). It also adds a --strict flag to treat external link errors as fatal when needed.

closes: #36

Key Changes

  • New exit code system: Created ExitCode enum with three states:

    • 0 (Success): No errors
    • 1 (Fatal): Internal errors or missing arguments
    • 2 (Warning): External link errors only (DNS failures, certificate errors, etc.)
  • Enhanced CrawlAggregateError:

    • Added hasOnlyExternalErrors property to distinguish error types
    • Updated error message to include breakdown of internal vs external errors
    • Added isCrawlerExternalError() type guard to classify errors
  • New --strict flag:

    • Added to both crawl and pipeline commands
    • When enabled, treats external link errors as fatal (exit code 1)
    • Allows CI/CD pipelines to tolerate temporary external link failures by default
  • Error handling in pipeline:

    • Catches CrawlAggregateError with only external errors
    • Exits with code 2 (Warning) unless --strict is specified
    • Propagates other errors normally
  • Updated CrawlerError type: Added isExternal field to distinguish between external and internal errors at the crawler level

  • Global error handler: Added try-catch in main CLI entry point to format and handle uncaught errors consistently

Implementation Details

  • External errors are identified by checking CrawlerError.isExternal field; plain Error objects are treated as internal
  • Error messages now include a breakdown: "Crawl completed with 3 error(s) (2 internal, 1 external)."
  • The --strict flag is passed through the entire pipeline from CLI flags to the crawl command
  • Comprehensive test coverage added for all exit code scenarios and error classification logic

https://claude.ai/code/session_01HtVd24jAUKYMjuMu1wgJs4

claude added 4 commits March 6, 2026 09:18
Distinguish between fatal errors (exit 1) and warnings (exit 2) so that
external link failures (DNS, certificate expiry) no longer fail CI when
the crawl itself succeeded.

- Add exit code constants: Success(0), Fatal(1), Warning(2)
- Classify CrawlerError with isExternal flag in crawler package
- CrawlAggregateError.hasOnlyExternalErrors for error classification
- Add --strict flag to crawl/pipeline to treat external errors as fatal
- Add global error handler in CLI entry point
- Improved error summary output (internal/external breakdown)

Closes #36

https://claude.ai/code/session_01HtVd24jAUKYMjuMu1wgJs4
- Strengthen isCrawlerExternalError type guard with pid check
- Include internal/external breakdown in CrawlAggregateError.message
- Add tests: empty array edge case, message format, formatCrawlErrors output
- Add test: resumeCrawl exit code path for external errors
- Replace magic number 1 with ExitCode.Fatal in pipeline test

https://claude.ai/code/session_01HtVd24jAUKYMjuMu1wgJs4
- README: add --strict to crawl options table
- README: add exit code table with CI usage examples
- README: mention --strict in pipeline options
- ARCHITECTURE: add CLI exit code section with error classification flow

https://claude.ai/code/session_01HtVd24jAUKYMjuMu1wgJs4
README: Add pipeline-specific CI examples with --strict and exit code
cross-reference to the crawl section.
ARCHITECTURE: Clarify that both crawl and pipeline commands share the
same exit code behavior.

https://claude.ai/code/session_01HtVd24jAUKYMjuMu1wgJs4
@YusukeHirao YusukeHirao merged commit 5832276 into main Mar 9, 2026
3 checks passed
@YusukeHirao YusukeHirao deleted the claude/improve-exit-codes-mZbmV branch March 9, 2026 08:33
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.

Enhancement(cli): exit code の粒度を改善する

2 participants