Commit 89824642 authored by Kamil Trzciński's avatar Kamil Trzciński

Add `QueryAnalyzerError` based on `Exception` to raise in tests

We use `Exception` since in tests we have very often very wide resuces.
Wide exception ensures that we correctly will raise it in tests.
parent 185222aa
...@@ -61,7 +61,7 @@ module Gitlab ...@@ -61,7 +61,7 @@ module Gitlab
next if analyzer.suppressed? next if analyzer.suppressed?
analyzer.analyze(parsed) analyzer.analyze(parsed)
rescue StandardError => e rescue StandardError, QueryAnalyzers::Base::QueryAnalyzerError => e
# We catch all standard errors to prevent validation errors to introduce fatal errors in production # We catch all standard errors to prevent validation errors to introduce fatal errors in production
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e) Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e)
end end
...@@ -75,7 +75,7 @@ module Gitlab ...@@ -75,7 +75,7 @@ module Gitlab
true true
end end
rescue StandardError => e rescue StandardError, QueryAnalyzers::Base::QueryAnalyzerError => e
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e) Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e)
false false
...@@ -88,7 +88,7 @@ module Gitlab ...@@ -88,7 +88,7 @@ module Gitlab
def end! def end!
enabled_analyzers.select do |analyzer| enabled_analyzers.select do |analyzer|
analyzer.end! analyzer.end!
rescue StandardError => e rescue StandardError, QueryAnalyzers::Base::QueryAnalyzerError => e
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e) Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e)
end end
......
...@@ -4,6 +4,9 @@ module Gitlab ...@@ -4,6 +4,9 @@ module Gitlab
module Database module Database
module QueryAnalyzers module QueryAnalyzers
class Base class Base
# `Exception` to ensure that is not easily rescued when running in test env
QueryAnalyzerError = Class.new(Exception) # rubocop:disable Lint/InheritException
def self.suppressed? def self.suppressed?
Thread.current[self.suppress_key] Thread.current[self.suppress_key]
end end
......
...@@ -4,7 +4,7 @@ module Gitlab ...@@ -4,7 +4,7 @@ module Gitlab
module Database module Database
module QueryAnalyzers module QueryAnalyzers
class PreventCrossDatabaseModification < Database::QueryAnalyzers::Base class PreventCrossDatabaseModification < Database::QueryAnalyzers::Base
CrossDatabaseModificationAcrossUnsupportedTablesError = Class.new(StandardError) CrossDatabaseModificationAcrossUnsupportedTablesError = Class.new(QueryAnalyzerError)
# This method will allow cross database modifications within the block # This method will allow cross database modifications within the block
# Example: # Example:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment