Skip to content

Commit

Permalink
fix #479 by improving composed error backtraces and bump to 3.8.2
Browse files Browse the repository at this point in the history
Big thanks to @robturtle and his original PR (#481) for steering me
toward this solution.
  • Loading branch information
AaronLasseigne committed Apr 22, 2020
1 parent b8bd3e1 commit 66e9c8b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# [3.8.2][] (2020-04-22)

## Fixed

- [479][] Composed interactions that throw errors now show a complete backtrace instead of ending at the `run!` of the outermost interaction.

# [3.8.1][] (2020-04-04)

## Fixed
Expand Down Expand Up @@ -765,6 +771,7 @@ Example.run

- Initial release.

[3.8.2]: https://github.com/AaronLasseigne/active_interaction/compare/v3.8.1...v3.8.2
[3.8.1]: https://github.com/AaronLasseigne/active_interaction/compare/v3.8.0...v3.8.1
[3.8.0]: https://github.com/AaronLasseigne/active_interaction/compare/v3.7.1...v3.8.0
[3.7.1]: https://github.com/AaronLasseigne/active_interaction/compare/v3.7.0...v3.7.1
Expand Down Expand Up @@ -963,3 +970,4 @@ Example.run
[#457]: https://github.com/AaronLasseigne/active_interaction/issues/457
[#477]: https://github.com/AaronLasseigne/active_interaction/issues/477
[#476]: https://github.com/AaronLasseigne/active_interaction/issues/476
[#479]: https://github.com/AaronLasseigne/active_interaction/issues/479
2 changes: 2 additions & 0 deletions lib/active_interaction/concerns/runnable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def run
begin
execute
rescue Interrupt => interrupt
errors.backtrace = interrupt.errors.backtrace || interrupt.backtrace
errors.merge!(interrupt.errors)
end
end
Expand All @@ -94,6 +95,7 @@ def run!

e = InvalidInteractionError.new(errors.full_messages.join(', '))
e.interaction = self
e.set_backtrace(errors.backtrace) if errors.backtrace
raise e
end

Expand Down
2 changes: 2 additions & 0 deletions lib/active_interaction/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def initialize(errors)

# An extension that provides the ability to merge other errors into itself.
class Errors < ActiveModel::Errors
attr_accessor :backtrace

# Merge other errors into this one.
#
# @param other [Errors]
Expand Down
2 changes: 1 addition & 1 deletion lib/active_interaction/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ module ActiveInteraction
# The version number.
#
# @return [Gem::Version]
VERSION = Gem::Version.new('3.8.1')
VERSION = Gem::Version.new('3.8.2')
end
15 changes: 15 additions & 0 deletions spec/active_interaction/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def execute
class: Object,
default: nil

# NOTE: the relative position between this method
# and the compose line should be preserved.
def self.composition_location
"#{__FILE__}:#{__LINE__ + 4}:in `execute'"
end

def execute
compose(AddInteraction, x: x, y: z)
end
Expand Down Expand Up @@ -371,6 +377,15 @@ def execute
expect(outcome.errors.details)
.to eql(x: [{ error: :missing }], base: [{ error: 'Y is required' }])
end

it 'has the correct backtrace' do
begin
described_class.run!(inputs)
rescue ActiveInteraction::InvalidInteractionError => e
expect(e.backtrace)
.to include(InterruptInteraction.composition_location)
end
end
end
end

Expand Down

0 comments on commit 66e9c8b

Please sign in to comment.