-
Notifications
You must be signed in to change notification settings - Fork 5
fix: log debug output when commands fail #77
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
Open
rupayon123
wants to merge
5
commits into
albertalef:master
Choose a base branch
from
rupayon123:debug-log-stderr-on-failure
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+88
−13
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
31b1ed3
fix: log debug output for failed commands
rupayon123 704dae2
test: cover rescued debug command errors
rupayon123 533670a
fix: avoid shell conversion in rescued command spec
rupayon123 5e602ab
fix: satisfy debugger rubocop warnings
rupayon123 c3ba42d
fix: satisfy debugger rubocop warnings
rupayon123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,12 @@ | |
|
|
||
| expect(log_output.join).to include("Stdout: \"#{expected_output}\"") | ||
| end | ||
|
|
||
| it "logs the stderr" do | ||
| subject_method | ||
|
|
||
| expect(log_output.join).to include("Stderr: \"\"") | ||
| end | ||
| end | ||
|
|
||
| RSpec.shared_examples "a silent command" do | ||
|
|
@@ -83,7 +89,62 @@ def subject_method | |
| def subject_method | ||
| sh.echo("hello", _debug: true) | ||
| end | ||
|
|
||
| def run_failed_debug_command | ||
| sh.ruby("-e", "\"STDERR.write(%q{bad}); exit 1\"", _debug: true) | ||
| rescue RubyShell::CommandError | ||
| nil | ||
| end | ||
|
|
||
| def rescued_failed_debug_command | ||
| sh.ruby("-e", "\"STDOUT.write(%q{out}); STDERR.write(%q{bad}); exit 1\"", _debug: true) | ||
| nil | ||
| rescue RubyShell::CommandError => e | ||
| e | ||
| end | ||
|
|
||
| it_behaves_like "a logged command", "hello" | ||
|
|
||
| it "reraises failed commands" do | ||
| expect do | ||
| sh.ruby("-e", "\"STDERR.write(%q{bad}); exit 1\"", _debug: true) | ||
| end.to raise_error(RubyShell::CommandError) | ||
| end | ||
|
|
||
| it "logs failed command exit code before reraising" do | ||
| run_failed_debug_command | ||
| expect(log_output.join).to include("Exit code: 1") | ||
| end | ||
|
|
||
| it "logs failed command stdout before reraising" do | ||
| run_failed_debug_command | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can separate the |
||
| expect(log_output.join).to include("Stdout: \"\"") | ||
| end | ||
|
|
||
| it "logs failed command stderr before reraising" do | ||
| run_failed_debug_command | ||
| expect(log_output.join).to include("Stderr: \"bad\"") | ||
| end | ||
|
|
||
| it "keeps the rescued error type available" do | ||
| expect(rescued_failed_debug_command).to be_a(RubyShell::CommandError) | ||
| end | ||
|
|
||
| it "keeps the rescued error command available" do | ||
| expect(rescued_failed_debug_command.command.to_s).to include("STDOUT.write") | ||
| end | ||
|
|
||
| it "keeps the rescued error stdout available" do | ||
| expect(rescued_failed_debug_command.stdout).to eq("out") | ||
| end | ||
|
|
||
| it "keeps the rescued error stderr available" do | ||
| expect(rescued_failed_debug_command.stderr).to eq("bad") | ||
| end | ||
|
|
||
| it "keeps the rescued error status available" do | ||
| expect(rescued_failed_debug_command.status.exitstatus).to eq(1) | ||
| end | ||
| end | ||
|
|
||
| context "when debug mode is enabled globally" do | ||
|
|
@@ -104,4 +165,4 @@ def subject_method | |
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
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: