From 208409ed05cb9a7b6bb7d060dd53230ca2147911 Mon Sep 17 00:00:00 2001 From: Bruno Enten Date: Sun, 26 Nov 2023 23:03:47 +0100 Subject: [PATCH] Fix `reflex_data` keyword argument (#673) # Type of PR (feature, enhancement, bug fix, etc.) bug fix ## Description Rename named parameter, and change error message that was causing an exception in a rescue block. ## Why should this be added Stimulus reflex doesn't work at all without these fixes. ## Checklist - [X ] My code follows the style guidelines of this project - [ X] Checks (StandardRB & Prettier-Standard) are passing --- app/channels/stimulus_reflex/channel.rb | 3 ++- lib/stimulus_reflex/reflex.rb | 1 + lib/stimulus_reflex/reflex_factory.rb | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/channels/stimulus_reflex/channel.rb b/app/channels/stimulus_reflex/channel.rb index 04c10c0f..949bea4c 100644 --- a/app/channels/stimulus_reflex/channel.rb +++ b/app/channels/stimulus_reflex/channel.rb @@ -16,13 +16,14 @@ def receive(data) delegate_call_to_reflex reflex rescue => exception error = exception_with_backtrace(exception) - error_message = "\e[31mReflex #{reflex.data.target} failed: #{error[:message]} [#{reflex.url}]\e[0m\n#{error[:stack]}" if reflex + error_message = "\e[31mReflex #{reflex.data.target} failed: #{error[:message]} [#{reflex.url}]\e[0m\n#{error[:stack]}" reflex.rescue_with_handler(exception) reflex.logger&.error error_message reflex.broadcast_error data: data, error: "#{exception} #{exception.backtrace.first.split(":in ")[0] if Rails.env.development?}" else + error_message = "\e[31mReflex failed: #{error[:message]} \e[0m\n#{error[:stack]}" unless exception.is_a?(StimulusReflex::VersionMismatchError) StimulusReflex.config.logger.error error_message end diff --git a/lib/stimulus_reflex/reflex.rb b/lib/stimulus_reflex/reflex.rb index 445cb660..10fc0626 100644 --- a/lib/stimulus_reflex/reflex.rb +++ b/lib/stimulus_reflex/reflex.rb @@ -23,6 +23,7 @@ class StimulusReflex::Reflex # END TODO: remove alias_method :action_name, :method_name # for compatibility with controller libraries like Pundit that expect an action name + alias_method :data, :reflex_data def initialize(channel, reflex_data:) @channel = channel diff --git a/lib/stimulus_reflex/reflex_factory.rb b/lib/stimulus_reflex/reflex_factory.rb index 3c3adc5f..f587ba68 100644 --- a/lib/stimulus_reflex/reflex_factory.rb +++ b/lib/stimulus_reflex/reflex_factory.rb @@ -11,7 +11,7 @@ def initialize(channel, data) end def call - reflex_class.new(channel, data: data) + reflex_class.new(channel, reflex_data: data) end private