Skip to content

Commit bdace2f

Browse files
authored
Add parsed errors to default OutputError message (#36)
1 parent eb3b700 commit bdace2f

5 files changed

Lines changed: 41 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Opera Changelog
22

3+
### 0.4.1 - Feb 18, 2026
4+
- Add parsed errors to default `output!` exception message
5+
36
### 0.4.0 - May 22, 2025
47

58
- Stop handling exceptions

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
opera (0.4.0)
4+
opera (0.4.1)
55

66
GEM
77
remote: https://rubygems.org/

lib/opera/operation/result.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ def failures
3838
end
3939

4040
def output!
41-
raise OutputError.new('Cannot retrieve output from a Failure.', errors) if failure?
41+
if failure?
42+
errors_combined = errors.map do |key, messages|
43+
"- #{key}: #{messages.join('; ')}"
44+
end.join("\n")
45+
46+
raise OutputError.new("Operation failed — output cannot be retrieved.\n#{errors_combined}", errors)
47+
end
4248

4349
output
4450
end

lib/opera/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Opera
4-
VERSION = '0.4.0'
4+
VERSION = '0.4.1'
55
end

spec/opera/operation/result_spec.rb

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,38 @@ module Opera
3939
it { expect(subject.output!).to eq(:example) }
4040
end
4141

42-
context 'with Failure' do
43-
before { subject.add_error(:example, 'Example') }
42+
context 'with a single error' do
43+
before { subject.add_error(:example, 'Example error') }
4444

4545
it 'raises exception' do
4646
expect { subject.output! }.to raise_error(Opera::Operation::Result::OutputError) do |error|
47-
expect(error.message).to eq('Cannot retrieve output from a Failure.')
48-
expect(error.errors).to eq(example: ['Example'])
47+
expect(error.message).to eq(
48+
"Operation failed — output cannot be retrieved.\n- example: Example error"
49+
)
50+
expect(error.errors).to eq(example: ['Example error'])
51+
end
52+
end
53+
end
54+
55+
context 'with multiple errors' do
56+
before do
57+
subject.add_errors(
58+
example: ['Example error', 'Unexpected behavior'],
59+
other_example: ['Hello darkness, my old friend']
60+
)
61+
end
62+
63+
it 'raises exception' do
64+
expect { subject.output! }.to raise_error(Opera::Operation::Result::OutputError) do |error|
65+
expect(error.message).to eq(
66+
"Operation failed — output cannot be retrieved.\n" \
67+
"- example: Example error; Unexpected behavior\n" \
68+
"- other_example: Hello darkness, my old friend"
69+
)
70+
expect(error.errors).to eq(
71+
example: ['Example error', 'Unexpected behavior'],
72+
other_example: ['Hello darkness, my old friend']
73+
)
4974
end
5075
end
5176
end

0 commit comments

Comments
 (0)