Skip and report unparseable files in the @context search codemod#5324
Conversation
The codemod called transformContextSearch per file with no error handling, so a single module whose template the parser rejects threw out of the loop and aborted the entire run — masking every file after it. Running the codemod over a large body of card source is exactly where that bites. Wrap the per-file transform in try/catch: on a parse throw, record the file in a new "unparseable" bucket and continue. Such modules can't be migrated mechanically (and don't compile as-is), so they're left untouched and listed in a "Skipped unparseable file(s)" section at the end alongside the migrated and hand-migration reports. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R4n4P6G1vFdSvSZaKkFK5f
Host Test Results 1 files ±0 1 suites ±0 1h 41m 42s ⏱️ - 1m 32s Results for commit c2856f9. ± Comparison against earlier commit 5bf8304. Realm Server Test Results 1 files ±0 1 suites ±0 11m 10s ⏱️ -9s Results for commit c2856f9. ± Comparison against earlier commit 5bf8304. |
There was a problem hiding this comment.
Pull request overview
This PR improves the resilience of the realm-server @context search codemod CLI by continuing the sweep when a single .gts file can’t be parsed, and reporting those files separately instead of aborting the entire run.
Changes:
- Wraps
transformContextSearch()per-file execution intry/catchso a parse failure doesn’t terminate the whole run. - Tracks skipped parse-failures in a new
unparseablebucket and prints a dedicated “Skipped unparseable file(s)” report section.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address review feedback: `let result;` was an implicit `any` under realm-server's `noImplicitAny` (and `scripts/` is in the tsconfig `include`, so it would fail `lint:types`) — annotate it `TransformResult`. Also derive the skip-path message via `err instanceof Error ? err.message : String(err)` so a non-Error throw can't crash the report. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R4n4P6G1vFdSvSZaKkFK5f
The
@contextsearch codemod (packages/realm-server/scripts/codemod/context-search) calledtransformContextSearchper file with no error handling. A single module whose<template>the parser rejects threw out of the loop and aborted the entire run, masking every file after it — which is exactly what bites when sweeping a large body of card source.This wraps the per-file transform in
try/catch: on a parse throw the file is recorded in a newunparseablebucket and the sweep continues. Such modules can't be migrated mechanically (and don't compile as-is), so they're left untouched and surfaced in a new "Skipped unparseable file(s)" section alongside the existing migrated / hand-migration reports.Verified on a two-file fixture (one clean card + one with a malformed template): the codemod migrates the clean file, reports the malformed one as skipped, and exits 0 instead of aborting.
🤖 Generated with Claude Code
https://claude.ai/code/session_01R4n4P6G1vFdSvSZaKkFK5f