Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
opera (0.4.0)
opera (0.4.1)

GEM
remote: https://rubygems.org/
Expand Down
8 changes: 7 additions & 1 deletion lib/opera/operation/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/opera/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Opera
VERSION = '0.4.0'
VERSION = '0.4.1'
end
33 changes: 29 additions & 4 deletions spec/opera/operation/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down