Skip to content

Commit

Permalink
Report the command name for abort and include command in AbortError
Browse files Browse the repository at this point in the history
  • Loading branch information
hopsoft committed Jan 3, 2024
1 parent dd11ff3 commit 47ee410
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/turbo_boost/commands/command_callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions lib/turbo_boost/commands/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/turbo_boost/commands/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 47ee410

Please sign in to comment.