diff --git a/lib/turbo_boost/commands/command_callbacks.rb b/lib/turbo_boost/commands/command_callbacks.rb index 61804211..0e3d5a62 100644 --- a/lib/turbo_boost/commands/command_callbacks.rb +++ b/lib/turbo_boost/commands/command_callbacks.rb @@ -94,12 +94,12 @@ def callback_options(options) # `throw :abort` was invoked command.send :aborted!, - TurboBoost::Commands::AbortError.new(handler: command.method(:abort_handler)) + TurboBoost::Commands::AbortError.new(command: command) rescue UncaughtThrowError => error # `throw` was invoked without :abort message = "Please use `throw :abort` to abort a command." command.send :aborted!, - TurboBoost::Commands::AbortError.new(message, handler: command.method(:abort_handler), cause: error) + TurboBoost::Commands::AbortError.new(message, command: command, cause: error) rescue => error # unxpected error in callback command.send :errored!, error diff --git a/lib/turbo_boost/commands/errors.rb b/lib/turbo_boost/commands/errors.rb index 3b9b7224..22a49034 100644 --- a/lib/turbo_boost/commands/errors.rb +++ b/lib/turbo_boost/commands/errors.rb @@ -8,17 +8,12 @@ class InvalidMethodError < StandardError; end class InvalidElementError < StandardError; end class AbortError < StandardError - attr_reader :cause + attr_reader :cause, :command - def initialize(message = "Command aborted by a callback!", handler:, cause: nil) + def initialize(message = "Command aborted by a callback!", command:, cause: nil) super(message) - @handler = handler + @command = command @cause = cause end - - def location - path, line = @handler&.source_location || [] - "#{path.split("/").last}:#{line}" - end end end diff --git a/lib/turbo_boost/commands/runner.rb b/lib/turbo_boost/commands/runner.rb index 54294bf0..8b18fd5a 100644 --- a/lib/turbo_boost/commands/runner.rb +++ b/lib/turbo_boost/commands/runner.rb @@ -140,7 +140,7 @@ def prevent_controller_action(error: nil) render_response append_success_to_response when TurboBoost::Commands::AbortError - render_response status: 299, headers: {"TurboBoost-Abort": error.location} + render_response status: 299, headers: {"TurboBoost-Abort": command_name} else location = error.backtrace.first.to_s[/[^\/]+\.rb:\d+/i] render_response status: :internal_server_error,