Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print debugger output to the Ruby LSP output channel as well as the debug console #2957

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Dec 4, 2024

Motivation

Because the debug console is only available when the debugger is actually spawned and attached to, users often miss crucial debugging messages about the reason the debugger exits unexpectedly.

This commit prints all output to the Ruby LSP output channel as well as the debug console. So when the debugger exits unexpectedly, users can still see the output in the Ruby LSP output channel.

Example

Launching Rails server is a project where bin/rails is removed. In this case, because the debugger does not successfully start, DEBUG CONSOLE will have no output.

Before

2024-12-04 18:12:03.452 [info] Spawning debugger in directory /Users/hung-wulo/src/github.com/Shopify/code-db
2024-12-04 18:12:03.454 [info]    Command bundle exec rdbg --open --command -- bin/rails s
2024-12-04 18:12:03.454 [info]    Environment { envs... }

After

2024-12-04 18:10:22.510 [info] [debugger]: Spawning debugger in directory /Users/hung-wulo/src/github.com/Shopify/code-db
2024-12-04 18:10:22.510 [info] [debugger]:    Command bundle exec rdbg --open --command -- bin/rails s
2024-12-04 18:10:22.510 [info] [debugger]:    Environment { envs... }
2024-12-04 18:10:22.903 [info] [debugger]: bundler: failed to load command: rdbg (/Users/hung-wulo/.gem/ruby/3.3.1/bin/rdbg)
2024-12-04 18:10:22.903 [info] [debugger]: /Users/hung-wulo/.gem/ruby/3.3.1/gems/debug-1.9.2/exe/rdbg:36:in `exec': No such file or directory - bin/rails (Errno::ENOENT)
	from /Users/hung-wulo/.gem/ruby/3.3.1/gems/debug-1.9.2/exe/rdbg:36:in `<top (required)>'
	from /Users/hung-wulo/.gem/ruby/3.3.1/bin/rdbg:25:in `load'
	from /Users/hung-wulo/.gem/ruby/3.3.1/bin/rdbg:25:in `<top (required)>'
	from /Users/hung-wulo/.gem/ruby/3.3.1/gems/bundler-2.5.4/lib/bundler/cli/exec.rb:58:in `load'
	from /Users/hung-wulo/.gem/ruby/3.3.1/gems/bundler-2.5.4/lib/bundler/cli/exec.rb:58:in `kernel_load'
	from /Users/hung-wulo/.gem/ruby/3.3.1/gems/bundler-2.5.4/lib/bundler/cli/exec.rb:23:in `run'
	from /Users/hung-wulo/.gem/ruby/3.3.1/gems/bundler-2.5.4/lib/bundler/cli.rb:451:in `exec'
	from /Users/hung-wulo/.gem/ruby/3.3.1/gems/bundler-2.5.4/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
	from /Users/hung-wulo/.gem/ruby/3.3.1/gems/bundler-2.5.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/hung-wulo/.gem/ruby/3.3.1/gems/bundler-2.5.4/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
	from /Users/hung-wulo/.gem/ruby/3.3.1/gems/bundler-2.5.4/lib/bundler/cli.rb:34:in `dispatch'
	from /Users/hung-wulo/.gem/ruby/3.3.1/gems/bundler-2.5.4/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
	from /Users/hung-wulo/.gem/ruby/3.3.1/gems/bundler-2.5.4/lib/bundler/cli.rb:28:in `start'
	from /Users/hung-wulo/.gem/ruby/3.3.1/gems/bundler-2.5.4/exe/bundle:28:in `block in <top (required)>'
	from /Users/hung-wulo/.gem/ruby/3.3.1/gems/bundler-2.5.4/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from /Users/hung-wulo/.gem/ruby/3.3.1/gems/bundler-2.5.4/exe/bundle:20:in `<top (required)>'
	from /Users/hung-wulo/.gem/ruby/3.3.1/bin/bundle:25:in `load'
	from /Users/hung-wulo/.gem/ruby/3.3.1/bin/bundle:25:in `<main>'
2024-12-04 18:10:22.905 [info] [debugger]: Debugger exited with status 1. Check the Ruby LSP output channel for more information.

Implementation

Automated Tests

Manual Tests

…ebug console

Because the debug console is only available when the debugger is actually
spawned and attached to, users often miss crucial debugging messages about
the reason the debugger exits unexpectedly.

This commit prints all output to the Ruby LSP output channel as well as the
debug console. So when the debugger exits unexpectedly, users can still see
the output in the Ruby LSP output channel.
@st0012 st0012 requested a review from a team as a code owner December 4, 2024 18:13
@st0012 st0012 self-assigned this Dec 4, 2024
@st0012 st0012 added enhancement New feature or request vscode This pull request should be included in the VS Code extension's release notes labels Dec 4, 2024
this.logDebuggerMessage(`Spawning debugger in directory ${cwd}`);
this.logDebuggerMessage(` Command bundle ${args.join(" ")}`);
this.logDebuggerMessage(
` Environment ${JSON.stringify(configuration.env)}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the trailing comma accidental?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's required by linting rules:

Screenshot 2024-12-04 at 20 56 27

When I save the file, it's automatically added back.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it seems the linter is defaulting to an 80 character line limit.

@@ -341,4 +344,12 @@ export class Debugger
});
});
}

private logDebuggerMessage(message: string) {
const trimmedMessage = message.trimEnd();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the debugger prints messages containing a \n in the end, it'd create an empty line in the log, which takes up space and doesn't help understanding the message. So IMO it's better to remove them.

@st0012 st0012 merged commit 4f3bc8d into main Dec 4, 2024
39 checks passed
@st0012 st0012 deleted the improve-debugger-integration branch December 4, 2024 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request vscode This pull request should be included in the VS Code extension's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants