Skip to content

Commit

Permalink
Merge pull request #114 from mavenlink/repair-bad-error-message
Browse files Browse the repository at this point in the history
Don't try to read error message from file if we are writing to stderr
  • Loading branch information
xjunior authored Jan 3, 2025
2 parents 9bff269 + 76d4154 commit e106009
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/departure/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ def validate_status!
#
# @return [String]
def error_message
File.read(error_log_path)
if redirect_stderr
File.read(error_log_path)
else
''
end
end

# Logs when the execution started
Expand Down
20 changes: 16 additions & 4 deletions spec/departure/command_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
require 'spec_helper'

describe Departure::Command do
describe '#run' do
shared_examples_for '#run' do
let(:command) { 'pt-online-schema-change command' }
let(:error_log_path) { 'departure_error.log' }
let(:logger) do
instance_double(
Departure::Logger, write: true, say: true, write_no_newline: true
)
end
let(:redirect_stderr) { true }

let(:runner) { described_class.new(command, error_log_path, logger, redirect_stderr) }

Expand All @@ -30,7 +29,6 @@
end
let(:stdout) { temp_file.open }
let(:wait_thread) { instance_double(Thread, value: status) }
let(:expected_command) { "#{command} 2> #{error_log_path}" }

before do
allow(Open3).to(
Expand Down Expand Up @@ -87,7 +85,7 @@

it 'raises a Departure::Error' do
expect { runner.run }
.to raise_exception(Departure::Error, "ROTO\n")
.to raise_exception(Departure::Error, redirect_stderr ? "ROTO\n" : "")
end
end

Expand All @@ -112,4 +110,18 @@
end
end
end

context 'redirect_stderr = true' do
let(:redirect_stderr) { true }
let(:expected_command) { "#{command} 2> #{error_log_path}" }

it_should_behave_like '#run'
end

context 'redirect_stderr = false' do
let(:redirect_stderr) { false }
let(:expected_command) { "#{command} 2>&1" }

it_should_behave_like '#run'
end
end

0 comments on commit e106009

Please sign in to comment.