summaryrefslogtreecommitdiff
path: root/lib/gitlab/tracking/standard_context.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/tracking/standard_context.rb')
-rw-r--r--lib/gitlab/tracking/standard_context.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/gitlab/tracking/standard_context.rb b/lib/gitlab/tracking/standard_context.rb
index 542dc476526..05ddc7e26cc 100644
--- a/lib/gitlab/tracking/standard_context.rb
+++ b/lib/gitlab/tracking/standard_context.rb
@@ -7,6 +7,12 @@ module Gitlab
GITLAB_RAILS_SOURCE = 'gitlab-rails'
def initialize(namespace: nil, project: nil, user: nil, **extra)
+ if Feature.enabled?(:standard_context_type_check)
+ check_argument_type(:namespace, namespace, [Namespace])
+ check_argument_type(:project, project, [Project, Integer])
+ check_argument_type(:user, user, [User, DeployToken])
+ end
+
@namespace = namespace
@plan = namespace&.actual_plan_name
@project = project
@@ -54,6 +60,14 @@ module Gitlab
def project_id
project.is_a?(Integer) ? project : project&.id
end
+
+ def check_argument_type(argument_name, argument_value, allowed_classes)
+ return if argument_value.nil? || allowed_classes.any? { |allowed_class| argument_value.is_a?(allowed_class) }
+
+ exception = "Invalid argument type passed for #{argument_name}." \
+ " Should be one of #{allowed_classes.map(&:to_s)}"
+ Gitlab::ErrorTracking.track_and_raise_for_dev_exception(ArgumentError.new(exception))
+ end
end
end
end