fix: handle parse errors in rule scanner and loader gracefully#432
Conversation
Bun.Transpiler.transformSync() and import() throw AggregateError when .rules.ts files contain syntax errors. These were unhandled, causing archgate check to crash instead of reporting the file as blocked. Wrap transpiler, parser, and dynamic import calls in try-catch blocks and return structured violation results so the error surfaces as a check failure rather than an unhandled exception. Fixes Sentry issue 130690158. Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📜 Recent review details⏰ Context from checks skipped due to timeout. (11)
|
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title clearly summarizes the main change: graceful handling of parse errors in the rule scanner and loader. |
| Description check | ✅ Passed | The description matches the changeset and explains the error handling fix, affected code paths, and added tests. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Deploying archgate-cli with
|
| Latest commit: |
775c544
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d974146b.archgate-cli.pages.dev |
| Branch Preview URL: | https://claude-focused-mcclintock-ed.archgate-cli.pages.dev |
Code Coverage
Full HTML report available in workflow artifacts. Per-directory breakdown
|
# archgate ## [0.45.7](v0.45.6...v0.45.7) (2026-06-27) ### Bug Fixes * **deps:** update docs dependencies ([#437](#437)) ([e8f10c1](e8f10c1)) * handle parse errors in rule scanner and loader gracefully ([#432](#432)) ([7c384d2](7c384d2)), closes [#130690158](https://github.com/archgate/cli/issues/130690158) * resolve all knip unused dependency and unlisted binary warnings ([#434](#434)) ([d7690b2](d7690b2)) --- This PR was generated with [simple-release](https://github.com/TrigenSoftware/simple-release). <details> <summary>📄 Cheatsheet</summary> <br> You can configure the bot's behavior through a pull request comment using the `!simple-release/set-options` command. ### Command Format ````md !simple-release/set-options ```json { "bump": {}, "publish": {} } ``` ```` ### Useful Parameters #### Bump | Parameter | Type | Description | |-----------|------|-------------| | `version` | `string` | Force set specific version | | `as` | `'major' \| 'minor' \| 'patch' \| 'prerelease'` | Release type | | `prerelease` | `string` | Pre-release identifier (e.g., "alpha", "beta") | | `firstRelease` | `boolean` | Whether this is the first release | | `skip` | `boolean` | Skip version bump | | `byProject` | `Record<string, object>` | Per-project bump options for monorepos | #### Publish | Parameter | Type | Description | |-----------|------|-------------| | `skip` | `boolean` | Skip publishing | | `access` | `'public' \| 'restricted'` | Package access level | | `tag` | `string` | Tag for npm publication | ### Usage Examples #### Force specific version ````md !simple-release/set-options ```json { "bump": { "version": "2.0.0" } } ``` ```` #### Force major bump ````md !simple-release/set-options ```json { "bump": { "as": "major" } } ``` ```` #### Create alpha pre-release ````md !simple-release/set-options ```json { "bump": { "prerelease": "alpha" } } ``` ```` #### Publish with specific access and tag ````md !simple-release/set-options ```json { "bump": { "prerelease": "beta" }, "publish": { "access": "public", "tag": "beta" } } ``` ```` ### Access Restrictions The command can only be used by users with permissions: - repository owner - organization member - collaborator ### Notes - The last comment with `!simple-release/set-options` command takes priority - JSON must be valid, otherwise the command will be ignored - Parameters apply only to the current release execution - The command can be updated by editing the comment or adding a new one </details> <!-- Please do not edit this comment. simple-release-pull-request: true simple-release-branch-from: release simple-release-branch-to: main --> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Summary
AggregateError: Parse errorcrash duringarchgate checkwhen user.rules.tsfiles contain syntax errors (Sentry #130690158)Bun.Transpiler.transformSync(),meriyah.parseModule(), and dynamicimport()in try-catch blocks in the rule scanner and loaderblockedresults with actionable violation messages instead of crashingContext
When a
.rules.tsfile has a syntax error,Bun.Transpiler.transformSync()throws anAggregateErrorwithBuildMessageinner errors. This was unhandled in bothscanRuleSource()andscanImportedRuleSource(). Similarly, theimport()call inloadRuleAdrs()was unhandled — if a file somehow passes the scanner but fails at import time, it would also crash.The fix ensures all three error paths return violations pointing at line 1 of the offending file, surfacing the first inner error message for diagnostic clarity.
Test plan
scanRuleSourcereturns violation for unparseable source (2 cases)scanImportedRuleSourcereturns violation for unparseable sourceloadRuleAdrsreturns blocked result for.rules.tswith syntax errorsbun run validatepasses (lint, typecheck, format, test, ADR check, build)