Skip to content

Commit

Permalink
Add cmd status to exception (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
artofhuman committed May 26, 2022
1 parent 39b3ed4 commit 42e9d01
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/mini_magick/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def run(command, options = {})
stdout, stderr, status = execute(command, stdin: options[:stdin])

if status != 0 && options.fetch(:whiny, MiniMagick.whiny)
fail MiniMagick::Error, "`#{command.join(" ")}` failed with error:\n#{stderr}"
fail MiniMagick::Error, "`#{command.join(" ")}` failed with status: #{status} and error:\n#{stderr}"
end

$stderr.print(stderr) unless options[:stderr] == false
Expand Down
7 changes: 5 additions & 2 deletions spec/lib/mini_magick/shell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
expect(output).to eq ["stdout", "stderr", 0]
end

it "uses stderr for error messages" do
it "uses stderr and status for error messages" do
allow(subject).to receive(:execute).and_return(["", "stderr", 1])

expected_msg = "`foo` failed with status: 1 and error:\nstderr"

expect { subject.run(%W[foo]) }
.to raise_error(MiniMagick::Error, /`foo`.*stderr/m)
.to raise_error(MiniMagick::Error, expected_msg)
end

it "raises an error when executable wasn't found" do
Expand Down

0 comments on commit 42e9d01

Please sign in to comment.