Skip to content

Commit a60637d

Browse files
authored
Merge pull request #206 from keithdoggett/fix/telemetry-no-database
Rescue from `NoDatabaseError` around telemetry call
2 parents 25907ec + 90cf5f8 commit a60637d

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

lib/active_record/connection_adapters/cockroachdb_adapter.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,23 @@ def initialize(pool_config)
6363
adapter = pool_config.db_config.configuration_hash[:adapter]
6464
return if disable_telemetry || adapter != "cockroachdb"
6565

66-
with_connection do |conn|
67-
if conn.active?
68-
begin
69-
query = "SELECT crdb_internal.increment_feature_counter('ActiveRecord %d.%d')"
70-
conn.execute(query % [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR])
71-
rescue ActiveRecord::StatementInvalid
72-
# The increment_feature_counter built-in is not supported on this
73-
# CockroachDB version. Ignore.
74-
rescue StandardError => e
75-
conn.logger.warn "Unexpected error when incrementing feature counter: #{e}"
66+
67+
begin
68+
with_connection do |conn|
69+
if conn.active?
70+
begin
71+
query = "SELECT crdb_internal.increment_feature_counter('ActiveRecord %d.%d')"
72+
conn.execute(query % [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR])
73+
rescue ActiveRecord::StatementInvalid
74+
# The increment_feature_counter built-in is not supported on this
75+
# CockroachDB version. Ignore.
76+
rescue StandardError => e
77+
conn.logger.warn "Unexpected error when incrementing feature counter: #{e}"
78+
end
7679
end
7780
end
81+
rescue ActiveRecord::NoDatabaseError
82+
# Prevent failures on db creation and parallel testing.
7883
end
7984
end
8085
end

0 commit comments

Comments
 (0)