Improve CLI error reporting
This commit is contained in:
@@ -44,7 +44,7 @@ module Producer::Core
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a runtime error is raised' do
|
||||
context 'when an error is raised' do
|
||||
let(:recipe_file) { fixture_path_for 'recipes/raise.rb' }
|
||||
|
||||
it 'exits with a return status of 70' do
|
||||
@@ -52,9 +52,9 @@ module Producer::Core
|
||||
.to raise_error(SystemExit) { |e| expect(e.status).to eq 70 }
|
||||
end
|
||||
|
||||
it 'prints exception name and message and the error stream' do
|
||||
it 'prints a report to the error stream' do
|
||||
expect { trap_exit { run! } }
|
||||
.to output("RemoteCommandExecutionError: false\n").to_stderr
|
||||
.to output(/\ARemoteCommandExecutionError: false$/).to_stderr
|
||||
end
|
||||
end
|
||||
end
|
||||
|
50
spec/producer/core/error_formatter_spec.rb
Normal file
50
spec/producer/core/error_formatter_spec.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer
|
||||
module Core
|
||||
describe ErrorFormatter do
|
||||
let(:debug) { false }
|
||||
let(:force_cause) { [] }
|
||||
let(:options) { { debug: debug, force_cause: force_cause } }
|
||||
subject(:formatter) { described_class.new(options) }
|
||||
|
||||
describe '#debug?' do
|
||||
it 'returns false' do
|
||||
expect(formatter.debug?).to be false
|
||||
end
|
||||
|
||||
context 'when debug is enabled' do
|
||||
let(:debug) { true }
|
||||
|
||||
it 'returns true' do
|
||||
expect(formatter.debug?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#format' do
|
||||
let(:message) { 'some exception' }
|
||||
let(:exception) { Exception.new(message) }
|
||||
|
||||
before { exception.set_backtrace %w[back trace] }
|
||||
|
||||
it 'formats the message' do
|
||||
expect(formatter.format exception)
|
||||
.to match /^Exception: some exception$/
|
||||
end
|
||||
|
||||
it 'indents the backtrace' do
|
||||
expect(formatter.format exception).to match /^\s+back$/
|
||||
end
|
||||
|
||||
context 'filtering' do
|
||||
before { exception.set_backtrace %w[back trace /producer-core/lib/] }
|
||||
|
||||
it 'excludes producer code from the backtrace' do
|
||||
expect(formatter.format exception).not_to include 'producer-core'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user