Class: PactBroker::DB::LogQuietener

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/pact_broker/db/log_quietener.rb

Instance Method Summary collapse

Instance Method Details

#error(*args) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/pact_broker/db/log_quietener.rb', line 12

def error *args
  if error_is_about_table_not_existing?(args)
    __getobj__().debug(*reassure_people_that_this_is_expected(args))
  elsif foreign_key_error?(args)
    __getobj__().warn(*args)
  else
    __getobj__().error(*args)
  end
end

#error_is_about_table_not_existing?(args) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'lib/pact_broker/db/log_quietener.rb', line 22

def error_is_about_table_not_existing?(args)
  args.first.is_a?(String) &&
    ( args.first.include?("PG::UndefinedTable") ||
      args.first.include?("no such table") ||
      args.first.include?("no such view"))
end

#foreign_key_error?(args) ⇒ Boolean

Foreign key exceptions are almost always transitory and unreproducible by this stage

Returns:

  • (Boolean)


30
31
32
# File 'lib/pact_broker/db/log_quietener.rb', line 30

def foreign_key_error?(args)
  args.first.is_a?(String) && args.first.downcase.include?("foreign key")
end

#reassure_people_that_this_is_expected(args) ⇒ Object



34
35
36
37
38
# File 'lib/pact_broker/db/log_quietener.rb', line 34

def reassure_people_that_this_is_expected(args)
  message = args.shift
  message = message + " Don't panic. This happens when Sequel doesn't know if a table/view exists or not."
  [message] + args
end