Skip to content

fix: log debug output when commands fail#77

Open
rupayon123 wants to merge 5 commits into
albertalef:masterfrom
rupayon123:debug-log-stderr-on-failure
Open

fix: log debug output when commands fail#77
rupayon123 wants to merge 5 commits into
albertalef:masterfrom
rupayon123:debug-log-stderr-on-failure

Conversation

@rupayon123

Copy link
Copy Markdown

Fixes #73

Debug mode now logs the command details before re-raising RubyShell::CommandError, so failed commands still show what ran. I also included stderr in the debug output, as requested in the issue thread.

Checks:

  • ruby -c lib/rubyshell/debugger.rb
  • ruby -c lib/rubyshell/error.rb
  • ruby -c spec/debugger_spec.rb
  • manual debug failure check with ruby -Ilib

I could not run the full RSpec file locally because the rspec executable is not installed here.

@albertalef

Copy link
Copy Markdown
Owner

Hi!! Sorry for the delay. Im reviewing now

Comment thread lib/rubyshell/debugger.rb
rescue RubyShell::CommandError => e
time_two = Process.clock_gettime(Process::CLOCK_MONOTONIC)
log_command(command, time_two - time_one, e.status, e.stdout, e.stderr)
raise

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

In some situations on the past, i had some troubles with errors losing data when rescued.

This actual code will not give us problems, but. Lets add a test checking that when we have a command being rescued outside, with debug option true, the returned CommandError has the correct attributes. Like:

begin
  ls('error', _debug: true)
rescue => e
  puts e.command # => Correct command
  puts e.stdout # => Correct stdout
  # etc
end

@albertalef

Copy link
Copy Markdown
Owner

Nice! Now, check the cicd, there is some failures

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.

Debug mode when the command fails

2 participants