Improve error handling and test robustness across CLI and crawler#46
Merged
YusukeHirao merged 4 commits intomainfrom Mar 5, 2026
Merged
Improve error handling and test robustness across CLI and crawler#46YusukeHirao merged 4 commits intomainfrom
YusukeHirao merged 4 commits intomainfrom
Conversation
if文でラップされたexpect()を削除し、find()/filter()の結果を expect().toBeDefined() / expect().toBeGreaterThan(0) で明示的に アサートするように変更。条件がfalseの場合にテストがサイレントに パスする問題を解消。 対象ファイル: - options.e2e.ts: externalPage の存在を事前アサート - single-page.e2e.ts: aboutPages の要素数を事前アサート - scope.e2e.ts: docsPage の存在を事前アサート Closes #16 https://claude.ai/code/session_01Gz7eS3SnV1N6LakV8b7CxM
- startCrawl: process.exit(1)をCrawlAggregateError throwに変更し、 crawl CLIハンドラ側でcatchしてexit。pipelineからの呼び出しで エラーハンドリングが効くようにする - pipeline: --silent時にpipeline自身のconsole.logを抑制 - analyze-lighthouse: toErrorヘルパーで全例外を統一的にError化 - archive.spec.ts: try/finallyでクリーンアップを保護 - WriteQueue.enqueue: 型シグネチャを() => Promise<T> | Tに修正 - テスト追加: --silent抑制、drain()空キュー、clearHtmlPath失敗伝搬 https://claude.ai/code/session_01Gz7eS3SnV1N6LakV8b7CxM
- crawl.ts: resumeCrawlをtry/catchブロック内に移動し、 --resumeモードのCrawlAggregateErrorも適切にprocess.exit(1)する - pipeline.ts: フラグ定義重複に関するTODOコメントを追加 https://claude.ai/code/session_01Gz7eS3SnV1N6LakV8b7CxM
- pipeline.ts: process.exit(1)ではなく例外伝搬である旨に修正 - crawl.ts: CrawlAggregateErrorコンストラクタに@paramタグ追加 - database.ts: getJSON関数に@templateタグ追加 https://claude.ai/code/session_01Gz7eS3SnV1N6LakV8b7CxM
aedc80f to
9bee88b
Compare
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.
Summary
This PR improves error handling patterns and test reliability across the codebase by introducing proper error aggregation, better exception handling in async operations, and more robust test assertions.
closes: #16
Key Changes
Error Handling Improvements
crawlandpipelinecommands to throwCrawlAggregateErrorinstead of callingprocess.exit(1), allowing callers to handle errors programmatically. The error is caught at the CLI entry point and exits there.CrawlAggregateErrorClass: Created a custom error class that wraps multiple errors from crawl operations, providing structured error information to callers.toError()utility function to safely convert any thrown value (including non-Error types) into an Error instance, preserving stack traces for actual Errors.Test Improvements
toError()utility covering Error instances, strings, null, undefined, and Error subclasses.expect().toBeDefined()checks in e2e tests, making test failures more obvious and preventing silent test passes.drain()on empty queue to verify immediate resolution.CLI Enhancements
--silentflag support to thepipelinecommand to suppress console output during execution, useful for programmatic usage.Code Quality
enqueue()to accept both async and synchronous operations (Promise<T> | T), improving flexibility.pipeline.tsnoting flag definition duplication across commands and the need for manual synchronization.Implementation Details
process.exit()is called.toError()utility ensures that even unexpected non-Error throws are properly converted to Error instances with meaningful messages.https://claude.ai/code/session_01Gz7eS3SnV1N6LakV8b7CxM