diff --git a/CHANGELOG.md b/CHANGELOG.md index d3e077b..c4ad491 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Opera Changelog +### 0.4.1 - Feb 18, 2026 +- Add parsed errors to default `output!` exception message + ### 0.4.0 - May 22, 2025 - Stop handling exceptions diff --git a/Gemfile.lock b/Gemfile.lock index 9b55fb7..69d25c6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - opera (0.4.0) + opera (0.4.1) GEM remote: https://rubygems.org/ diff --git a/lib/opera/operation/result.rb b/lib/opera/operation/result.rb index 9d6b5c9..6daa06b 100644 --- a/lib/opera/operation/result.rb +++ b/lib/opera/operation/result.rb @@ -38,7 +38,13 @@ def failures end def output! - raise OutputError.new('Cannot retrieve output from a Failure.', errors) if failure? + if failure? + errors_combined = errors.map do |key, messages| + "- #{key}: #{messages.join('; ')}" + end.join("\n") + + raise OutputError.new("Operation failed — output cannot be retrieved.\n#{errors_combined}", errors) + end output end diff --git a/lib/opera/version.rb b/lib/opera/version.rb index 3f9300d..3121a41 100644 --- a/lib/opera/version.rb +++ b/lib/opera/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Opera - VERSION = '0.4.0' + VERSION = '0.4.1' end diff --git a/spec/opera/operation/result_spec.rb b/spec/opera/operation/result_spec.rb index 8e7affe..1da04b0 100644 --- a/spec/opera/operation/result_spec.rb +++ b/spec/opera/operation/result_spec.rb @@ -39,13 +39,38 @@ module Opera it { expect(subject.output!).to eq(:example) } end - context 'with Failure' do - before { subject.add_error(:example, 'Example') } + context 'with a single error' do + before { subject.add_error(:example, 'Example error') } it 'raises exception' do expect { subject.output! }.to raise_error(Opera::Operation::Result::OutputError) do |error| - expect(error.message).to eq('Cannot retrieve output from a Failure.') - expect(error.errors).to eq(example: ['Example']) + expect(error.message).to eq( + "Operation failed — output cannot be retrieved.\n- example: Example error" + ) + expect(error.errors).to eq(example: ['Example error']) + end + end + end + + context 'with multiple errors' do + before do + subject.add_errors( + example: ['Example error', 'Unexpected behavior'], + other_example: ['Hello darkness, my old friend'] + ) + end + + it 'raises exception' do + expect { subject.output! }.to raise_error(Opera::Operation::Result::OutputError) do |error| + expect(error.message).to eq( + "Operation failed — output cannot be retrieved.\n" \ + "- example: Example error; Unexpected behavior\n" \ + "- other_example: Hello darkness, my old friend" + ) + expect(error.errors).to eq( + example: ['Example error', 'Unexpected behavior'], + other_example: ['Hello darkness, my old friend'] + ) end end end