Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentError for LightService::LocalizationAdapter #262

Open
wqsaali opened this issue Jan 10, 2025 · 1 comment
Open

ArgumentError for LightService::LocalizationAdapter #262

wqsaali opened this issue Jan 10, 2025 · 1 comment

Comments

@wqsaali
Copy link

wqsaali commented Jan 10, 2025

Problem

LightService::LocalizationAdapter methods success and failure are called with wrong number of arguments

light-service-0.19.0/lib/light-service/localization_adapter.rb:3:in `failure': wrong number of arguments (given 3, expected 2) (ArgumentError)

Code to reproduce this issue

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'light-service'
end

######################################################
# Patch Array and String to support .blank? and .underscore methods
######################################################
class Array
  def blank?
    empty?
  end
end

class String
  def underscore
    self.gsub(/::/, '/')
        .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
        .gsub(/([a-z\d])([A-Z])/, '\1_\2')
        .tr("-", "_")
        .downcase
  end
end
###############################################


###########
# Actual code
##########
class TestOrganizer
  extend LightService::Organizer

  def self.call(order)
    with(:order => order).reduce(
        TestAction,
      )
  end
end

class TestAction
  extend LightService::Action
  expects :order
  promises :result

  executed do |context|
    raise 'Exception'
  rescue => e
    context.fail_and_return!("Error: #{e.message}")
  end
end

TestOrganizer.call(1)

What's wrong in code

localization_adapter method is calling localization adapter based on condition

def localization_adapter
@localization_adapter ||= if Module.const_defined?('I18n')
LightService::I18n::LocalizationAdapter.new
else
LocalizationAdapter.new
end
end

Module.const_defined?('I18n') is always true when we include activesupport and never use LocalizationAdapter.new. If we don't use activesupport then LocalizationAdapter.new is called.

Code is calling success and failure methods with three arguements

@message = Configuration.localization_adapter.success(message,
current_action,
options)

@message = Configuration.localization_adapter.failure(message,
current_action,
options)

However, LocalizationAdapter.new has methods with two arguments

class LocalizationAdapter
def failure(message_or_key, action_class)
find_translated_message(message_or_key,
action_class.to_s.underscore,
:failures)

def success(message_or_key, action_class)
find_translated_message(message_or_key,
action_class.to_s.underscore,
:successes)

Error brought in by #238

@wqsaali wqsaali changed the title ArgumentError for LightService::LocalizationAdaptor ArgumentError for LightService::LocalizationAdapter Jan 10, 2025
@adomokos
Copy link
Owner

Mind creating a PR to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants