diff --git a/lib/gitlab_settings/options.rb b/lib/gitlab_settings/options.rb index de3b6e50ccc98f452027224b80e7f120326f195b..685557944364aa5e8d1a56b4c0f9ace65c9f80a5 100644 --- a/lib/gitlab_settings/options.rb +++ b/lib/gitlab_settings/options.rb @@ -121,10 +121,9 @@ def to_hash # Don't alter the internal keys def stringify_keys! - error_msg = "Warning: Do not mutate #{self.class} objects" - raise "#{error_msg}: `#{__method__}`" unless Rails.env.production? + error_msg = "Warning: Do not mutate #{self.class} objects: `#{__method__}`" - Gitlab::AppLogger.warn(error_msg, method: __method__) + Gitlab::ErrorTracking.track_and_raise_for_dev_exception(RuntimeError.new(error_msg), method: __method__) to_hash.deep_stringify_keys end @@ -132,10 +131,9 @@ def stringify_keys! # Don't alter the internal keys def symbolize_keys! - error_msg = "Warning: Do not mutate #{self.class} objects" - raise "#{error_msg}: `#{__method__}`" unless Rails.env.production? + error_msg = "Warning: Do not mutate #{self.class} objects: `#{__method__}`" - Gitlab::AppLogger.warn(error_msg, method: __method__) + Gitlab::ErrorTracking.track_and_raise_for_dev_exception(RuntimeError.new(error_msg), method: __method__) to_hash.deep_symbolize_keys end @@ -151,10 +149,9 @@ def method_missing(name, *args, &block) end if @options.respond_to?(name) - error_msg = "Calling a hash method on #{self.class}" - raise "#{error_msg}: `#{name}`" unless Rails.env.production? + error_msg = "Calling a hash method on #{self.class}: `#{name}`" - Gitlab::AppLogger.warn(error_msg, method: name) + Gitlab::ErrorTracking.track_and_raise_for_dev_exception(RuntimeError.new(error_msg), method: name) return @options.public_send(name, *args, &block) # rubocop: disable GitlabSecurity/PublicSend end diff --git a/spec/lib/gitlab_settings/options_spec.rb b/spec/lib/gitlab_settings/options_spec.rb index cd5a0adeecf332a9fd2744f0ab0239e270dab854..abb895032c9bf8b235cc51dbd08d7368cdd2bcb9 100644 --- a/spec/lib/gitlab_settings/options_spec.rb +++ b/spec/lib/gitlab_settings/options_spec.rb @@ -12,9 +12,10 @@ it 'returns the unchanged internal hash' do stub_rails_env('production') - expect(Gitlab::AppLogger) - .to receive(:warn) - .with('Warning: Do not mutate GitlabSettings::Options objects', method: method) + expect(Gitlab::ErrorTracking) + .to receive(:track_and_raise_for_dev_exception) + .with(RuntimeError.new("Warning: Do not mutate GitlabSettings::Options objects: `#{method}`"), method: method) + .and_call_original expect(options.send(method)).to be_truthy end @@ -233,9 +234,10 @@ it 'delegates the method to the internal options hash' do stub_rails_env('production') - expect(Gitlab::AppLogger) - .to receive(:warn) - .with('Calling a hash method on GitlabSettings::Options', method: :delete) + expect(Gitlab::ErrorTracking) + .to receive(:track_and_raise_for_dev_exception) + .with(RuntimeError.new('Calling a hash method on GitlabSettings::Options: `delete`'), method: :delete) + .and_call_original expect { options.foo.delete('bar') } .to change { options.to_hash }