Make extension activation resilient to setup failures#34
Merged
Conversation
Commands (`iwyu.run.one`, `iwyu.run.all`) were registered at the very end of the Extension constructor, after fallible setup (compile_commands parsing, user-supplied regexes, diagnostics refresh). If any of that threw, activation aborted before registration and invoking a command failed with `command 'iwyu.run.one' not found`, while the IWYU output channel only showed "Extension activated" (the real error went to the Extension Host log). - Register the commands first in the constructor so they survive setup errors. - Guard `new RegExp(...)` for `iwyu.fix.ignore_re`, `iwyu.fix.only_re` and `iwyu.diagnostics.include_guard_files`; log and ignore invalid patterns instead of throwing. - Wrap the activation body in try/catch and log failures to the IWYU output channel so they are visible to users. Fixes #26 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Fab-Cat
approved these changes
May 30, 2026
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
Fixes #26 (
Error: command 'iwyu.run.one' not found).The reporter saw only "Extension activated" in the IWYU output channel, yet running the command failed with
command 'iwyu.run.one' not found.Root cause
The commands (
iwyu.run.one,iwyu.run.all) were registered at the very end of theExtensionconstructor, after a chain of fallible setup:compile_commands.jsonhandling, user-supplied regex compilation, and a diagnostics refresh on the active editor. If any of that threw, the exception propagated out ofactivate()before the commands were registered. VS Code logs such uncaught activation errors to the Extension Host log — not the IWYU output channel — so the user only saw "Extension activated" and the commands were simply missing.The most likely trigger is the unguarded
new RegExp(...)calls built from theiwyu.fix.ignore_re,iwyu.fix.only_reandiwyu.diagnostics.include_guard_filessettings: an invalid pattern throws synchronously during construction.Changes
Testing
npm run compileandnpm run lintpass.npm test) could not run in the sandboxed environment — Electron rejects the test runner's--no-sandboxflags and never launches. No code paths in the test suite are affected by this change's structure.A follow-up for the reporter: their
iwyu.*settings + Extension Host log would confirm the exact trigger, butactivate()will now surface it in the IWYU output regardless.🤖 Generated with Claude Code