Skip to content

[Repo Assist] fix: replace console.group/time with VS Code OutputChannel for debug logging#124

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/fix-issue-14-debug-output-channel-2026-04-02-c77d8123c258c0f9
Draft

[Repo Assist] fix: replace console.group/time with VS Code OutputChannel for debug logging#124
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/fix-issue-14-debug-output-channel-2026-04-02-c77d8123c258c0f9

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 2, 2026

🤖 This is an automated pull request from Repo Assist.

Problem

Closes #14

When "phpcbf.debug": true is set, the extension crashes with:

TypeError: console.group is not a function

This occurs because VS Code's extension host does not expose console.group(), console.time(), console.timeEnd(), or console.groupEnd() in some versions/environments.

Additionally, the debug output was silently discarded:

  • phpcbfError was set inside an async exit callback but checked synchronously right after the Promise setup (always false), so the stdout listener for error output was never registered — error output from phpcbf was completely swallowed.
  • Exit code 3 set phpcbfError = true but never called resolve()/reject(), leaving the Promise permanently unresolved (hang), and in strict mode the undeclared phpcbfError assignment would throw a ReferenceError.

Root cause

The extension used browser-style console.group/console.time APIs that are not part of VS Code's extension host sandbox.

Fix

  • Add a _debugLog(message) helper on the PHPCBF class that writes to a VS Code OutputChannel (View → Output → phpcbf), with a console.log fallback for testing outside VS Code.
  • Replace all console.group, console.time, console.timeEnd, console.groupEnd calls with _debugLog().
  • Replace stderr console.log with _debugLog() so stderr is always visible in the Output panel (not just in debug mode).
  • Remove the broken phpcbfError stdout-capture pattern; stdout is now streamed directly to _debugLog when debug is enabled.
  • Fix exit code 3: call reject() so the Promise settles and show a window.showErrorMessage notification.
  • Create the OutputChannel in activate() and push it to context.subscriptions for proper cleanup.

Trade-offs

Debug output now appears in View → Output → phpcbf instead of the developer console. This is the VS Code-recommended approach and produces cleaner, always-accessible output for users.

Test Status

✅ All 7 unit tests pass (npm run test:unit).

No new tests were added for this change — the debug path requires a live VS Code extension host and phpcbf binary. The fix eliminates the crash that was reported and removes dead code.

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

…logging

Fixes issue #14 ('TypeError: console.group is not a function').

Problems fixed:
- console.group(), console.time(), console.timeEnd(), console.groupEnd()
  are not available in all VS Code extension host environments and throw
  TypeError when debug mode is enabled.
- The phpcbfError stdout-capture pattern was completely broken: the flag
  was set inside an async callback but checked synchronously immediately
  after, so the stdout listener was never registered.
- Exit code 3 left the Promise unresolved (hung), and referenced the
  removed phpcbfError variable which would throw in strict mode.

Changes:
- Add _debugLog() helper that writes to a VS Code OutputChannel (visible
  under View → Output → phpcbf) with a console.log fallback.
- Replace console.group/time/timeEnd/groupEnd with _debugLog() calls.
- Replace stderr console.log with _debugLog() so stderr is always
  captured in the Output panel (not just in debug mode).
- Remove the dead phpcbfError pattern; stdout is now always streamed to
  _debugLog when debug is enabled.
- Fix exit code 3: call reject() so the Promise settles and show an
  error notification.
- Create OutputChannel in activate() and pass it to PHPCBF constructor.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Apr 2, 2026
Summarises all bug fixes that are ready to ship, drawn from the
open Repo Assist PRs (primarily #106, #114, #117, #120, #124 and
the earlier consolidated fixes).

The version number in package.json is intentionally not changed here
(that file requires maintainer action due to protected-file
restrictions). This PR exists so the maintainer can review the
intended release notes and bump the version when ready.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In 0.0.8, debug fails. TypeError: console.group is not a function

0 participants