Skip to content

Make extension activation resilient to setup failures#34

Merged
helly25 merged 2 commits into
mainfrom
fix/issue-26-activation-resilience
May 30, 2026
Merged

Make extension activation resilient to setup failures#34
helly25 merged 2 commits into
mainfrom
fix/issue-26-activation-resilience

Conversation

@helly25
Copy link
Copy Markdown
Owner

@helly25 helly25 commented May 30, 2026

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 the Extension constructor, after a chain of fallible setup: compile_commands.json handling, user-supplied regex compilation, and a diagnostics refresh on the active editor. If any of that threw, the exception propagated out of activate() 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 the iwyu.fix.ignore_re, iwyu.fix.only_re and iwyu.diagnostics.include_guard_files settings: an invalid pattern throws synchronously during construction.

Changes

  • Register commands first in the constructor, so they remain available even if later setup fails.
  • Guard regex compilation via a small helper that logs and ignores invalid patterns instead of throwing.
  • Wrap the activation body in try/catch and log failures to the IWYU output channel, so future activation errors are visible to users instead of disappearing into the Extension Host log.

Testing

  • npm run compile and npm run lint pass.
  • The VS Code integration tests (npm test) could not run in the sandboxed environment — Electron rejects the test runner's --no-sandbox flags 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, but activate() will now surface it in the IWYU output regardless.

🤖 Generated with Claude Code

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>
@helly25 helly25 requested a review from Fab-Cat May 30, 2026 17:57
@helly25 helly25 merged commit 707efce into main May 30, 2026
2 checks passed
@helly25 helly25 deleted the fix/issue-26-activation-resilience branch May 30, 2026 18:03
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.

Error: command 'iwyu.run.one' not found

2 participants