Verdict::ExperimentHandleNotUnique
Closed this issue · 1 comments
xavi commented
When trying to deploy my first experiment with Verdict to a production server I get...
bundler: failed to load command: puma (/app/vendor/cache/bin/puma)
Verdict::ExperimentHandleNotUnique: Another experiment with handle "fake_name_ab_test" is already defined!
The web app works in my dev environment. But I've also seen the same error in dev when running some rake tasks (specifically, rails rails_rbi:all
, from https://github.com/chanzuckerberg/sorbet-rails).
This is the code...
components/public/app/ab_tests/public/fake_name_ab_test.rb
# typed: ignore
module Public
class FakeNameAbTest < Public::Experiments::BaseExperiment
define :fake_name_ab_test do
# ...
end
end
end
components/public/app/services/public/experiments/base_experiment.rb
# typed: ignore
module Public
module Experiments
class BaseExperiment < Verdict::Experiment
def initialize(handle, options = {}, &block)
super(
handle,
options.merge({ event_logger: Public::Experiments::Logger.new }),
&block
)
end
end
end
end
config/application.rb
# ...
class Application < Rails::Application
# ...
Verdict.directory = Rails.root.join('components', 'public', 'app', 'ab_tests', 'public')
end
# ...
In case it's relevant, components/public/
is a Rails engine.
There's only 1 experiment with the handle "fake_name_ab_test", so why the error...?
Verdict::ExperimentHandleNotUnique: Another experiment with handle "fake_name_ab_test" is already defined!
xavi commented
We worked around this by changing the fake_name_ab_test.rb above to...
# typed: ignore
unless Verdict.repository.key?('fake_name_ab_test')
Public::Experiments::BaseExperiment.define 'fake_name_ab_test' do
# ...
end
end