Refactoring: Improved error logging
- Remove unnecessary "ERROR" prefix - Log missing ES index as WARN instead of INFO - Log actual JSON ES payload in cases of an error (for e.g. manual cURL replaying) if possible
This commit is contained in:
parent
16fec3d888
commit
0004c72624
13 changed files with 28 additions and 25 deletions
|
@ -118,9 +118,9 @@ returns
|
||||||
# store unprocessable email for bug reporting
|
# store unprocessable email for bug reporting
|
||||||
filename = archive_mail('unprocessable_mail', msg)
|
filename = archive_mail('unprocessable_mail', msg)
|
||||||
|
|
||||||
message = "ERROR: Can't process email, you will find it for bug reporting under #{filename}, please create an issue at https://github.com/zammad/zammad/issues"
|
message = "Can't process email, you will find it for bug reporting under #{filename}, please create an issue at https://github.com/zammad/zammad/issues"
|
||||||
|
|
||||||
p message # rubocop:disable Rails/Output
|
p 'ERROR: ' + message # rubocop:disable Rails/Output
|
||||||
p 'ERROR: ' + e.inspect # rubocop:disable Rails/Output
|
p 'ERROR: ' + e.inspect # rubocop:disable Rails/Output
|
||||||
Rails.logger.error message
|
Rails.logger.error message
|
||||||
Rails.logger.error e
|
Rails.logger.error e
|
||||||
|
|
|
@ -120,8 +120,8 @@ module Channel::Filter::IdentifySender
|
||||||
# parse not parsable fields by mail gem like
|
# parse not parsable fields by mail gem like
|
||||||
# - Max Kohl | [example.com] <kohl@example.com>
|
# - Max Kohl | [example.com] <kohl@example.com>
|
||||||
# - Max Kohl <max.kohl <max.kohl@example.com>
|
# - Max Kohl <max.kohl <max.kohl@example.com>
|
||||||
Rails.logger.error 'ERROR: ' + e.inspect
|
Rails.logger.error e
|
||||||
Rails.logger.error "ERROR: try it by my self (#{item}): #{mail[item.to_sym]}"
|
Rails.logger.error "try it by my self (#{item}): #{mail[item.to_sym]}"
|
||||||
recipients = mail[item.to_sym].to_s.split(',')
|
recipients = mail[item.to_sym].to_s.split(',')
|
||||||
recipients.each do |recipient|
|
recipients.each do |recipient|
|
||||||
address = nil
|
address = nil
|
||||||
|
|
|
@ -26,7 +26,7 @@ module Channel::Filter::SenderIsSystemAddress
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.error 'ERROR: SenderIsSystemAddress: ' + e.inspect
|
Rails.logger.error 'SenderIsSystemAddress: ' + e.inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
# check if sender is agent
|
# check if sender is agent
|
||||||
|
@ -41,7 +41,7 @@ module Channel::Filter::SenderIsSystemAddress
|
||||||
mail['x-zammad-article-sender'.to_sym] = 'Agent'
|
mail['x-zammad-article-sender'.to_sym] = 'Agent'
|
||||||
return true
|
return true
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.error 'ERROR: SenderIsSystemAddress: ' + e.inspect
|
Rails.logger.error 'SenderIsSystemAddress: ' + e.inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
|
@ -17,7 +17,7 @@ class ExternalSync < ApplicationModel
|
||||||
object[attribute] = value
|
object[attribute] = value
|
||||||
changed ||= true
|
changed ||= true
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.error "ERROR: Unable to assign attribute #{attribute} to object #{object.class.name}: #{e.inspect}"
|
Rails.logger.error "Unable to assign attribute #{attribute} to object #{object.class.name}: #{e.inspect}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
changed
|
changed
|
||||||
|
|
|
@ -393,7 +393,7 @@ use "force: true" to delete also not editable fields
|
||||||
elsif data[:object_lookup_id]
|
elsif data[:object_lookup_id]
|
||||||
data[:object] = ObjectLookup.by_id(data[:object_lookup_id])
|
data[:object] = ObjectLookup.by_id(data[:object_lookup_id])
|
||||||
else
|
else
|
||||||
raise 'ERROR: need object or object_lookup_id param!'
|
raise 'need object or object_lookup_id param!'
|
||||||
end
|
end
|
||||||
|
|
||||||
data[:name].downcase!
|
data[:name].downcase!
|
||||||
|
@ -404,17 +404,17 @@ use "force: true" to delete also not editable fields
|
||||||
name: data[:name],
|
name: data[:name],
|
||||||
)
|
)
|
||||||
if !record
|
if !record
|
||||||
raise "ERROR: No such field #{data[:object]}.#{data[:name]}"
|
raise "No such field #{data[:object]}.#{data[:name]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if !data[:force] && !record.editable
|
if !data[:force] && !record.editable
|
||||||
raise "ERROR: #{data[:object]}.#{data[:name]} can't be removed!"
|
raise "#{data[:object]}.#{data[:name]} can't be removed!"
|
||||||
end
|
end
|
||||||
|
|
||||||
# check to make sure that no triggers, overviews, or schedulers references this attribute
|
# check to make sure that no triggers, overviews, or schedulers references this attribute
|
||||||
if ObjectManager::Attribute.attribute_used_by_references?(data[:object], data[:name])
|
if ObjectManager::Attribute.attribute_used_by_references?(data[:object], data[:name])
|
||||||
text = ObjectManager::Attribute.attribute_used_by_references_humaniced(data[:object], data[:name])
|
text = ObjectManager::Attribute.attribute_used_by_references_humaniced(data[:object], data[:name])
|
||||||
raise "ERROR: #{data[:object]}.#{data[:name]} is referenced by #{text} and thus cannot be deleted!"
|
raise "#{data[:object]}.#{data[:name]} is referenced by #{text} and thus cannot be deleted!"
|
||||||
end
|
end
|
||||||
|
|
||||||
# if record is to create, just destroy it
|
# if record is to create, just destroy it
|
||||||
|
|
|
@ -420,7 +420,7 @@ execute all pending package migrations at once
|
||||||
data = File.open(location, 'rb')
|
data = File.open(location, 'rb')
|
||||||
contents = data.read
|
contents = data.read
|
||||||
rescue => e
|
rescue => e
|
||||||
raise 'ERROR: ' + e.inspect
|
raise e
|
||||||
end
|
end
|
||||||
contents
|
contents
|
||||||
end
|
end
|
||||||
|
@ -462,7 +462,7 @@ execute all pending package migrations at once
|
||||||
file.close
|
file.close
|
||||||
File.chmod(permission.to_s.to_i(8), location)
|
File.chmod(permission.to_s.to_i(8), location)
|
||||||
rescue => e
|
rescue => e
|
||||||
raise 'ERROR: ' + e.inspect
|
raise e
|
||||||
end
|
end
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -347,7 +347,7 @@ class Scheduler < ApplicationModel
|
||||||
loop do
|
loop do
|
||||||
success, failure = Delayed::Worker.new.work_off
|
success, failure = Delayed::Worker.new.work_off
|
||||||
if failure.nonzero?
|
if failure.nonzero?
|
||||||
raise "ERROR: #{failure} failed background jobs: #{Delayed::Job.where('last_error IS NOT NULL').inspect}"
|
raise "#{failure} failed background jobs: #{Delayed::Job.where('last_error IS NOT NULL').inspect}"
|
||||||
end
|
end
|
||||||
break if success.zero?
|
break if success.zero?
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,7 +29,7 @@ class Store::Provider::File
|
||||||
# check sha
|
# check sha
|
||||||
local_sha = Digest::SHA256.hexdigest(get(sha))
|
local_sha = Digest::SHA256.hexdigest(get(sha))
|
||||||
if sha != local_sha
|
if sha != local_sha
|
||||||
raise "ERROR: Corrupt file in fs #{location}, sha should be #{sha} but is #{local_sha}"
|
raise "Corrupt file in fs #{location}, sha should be #{sha} but is #{local_sha}"
|
||||||
end
|
end
|
||||||
|
|
||||||
true
|
true
|
||||||
|
@ -40,7 +40,7 @@ class Store::Provider::File
|
||||||
location = get_location(sha)
|
location = get_location(sha)
|
||||||
Rails.logger.debug { "read from fs #{location}" }
|
Rails.logger.debug { "read from fs #{location}" }
|
||||||
if !File.exist?(location)
|
if !File.exist?(location)
|
||||||
raise "ERROR: No such file #{location}"
|
raise "No such file #{location}"
|
||||||
end
|
end
|
||||||
|
|
||||||
data = File.open(location, 'rb')
|
data = File.open(location, 'rb')
|
||||||
|
@ -49,7 +49,7 @@ class Store::Provider::File
|
||||||
# check sha
|
# check sha
|
||||||
local_sha = Digest::SHA256.hexdigest(content)
|
local_sha = Digest::SHA256.hexdigest(content)
|
||||||
if local_sha != sha
|
if local_sha != sha
|
||||||
raise "ERROR: Corrupt file in fs #{location}, sha should be #{sha} but is #{local_sha}"
|
raise "Corrupt file in fs #{location}, sha should be #{sha} but is #{local_sha}"
|
||||||
end
|
end
|
||||||
|
|
||||||
content
|
content
|
||||||
|
|
|
@ -1398,8 +1398,8 @@ result
|
||||||
begin
|
begin
|
||||||
next if recipient_email.match?(/#{send_no_auto_response_reg_exp}/i)
|
next if recipient_email.match?(/#{send_no_auto_response_reg_exp}/i)
|
||||||
rescue => e
|
rescue => e
|
||||||
logger.error "ERROR: Invalid regex '#{send_no_auto_response_reg_exp}' in setting send_no_auto_response_reg_exp"
|
logger.error "Invalid regex '#{send_no_auto_response_reg_exp}' in setting send_no_auto_response_reg_exp"
|
||||||
logger.error 'ERROR: ' + e.inspect
|
logger.error e
|
||||||
next if recipient_email.match?(/(mailer-daemon|postmaster|abuse|root|noreply|noreply.+?|no-reply|no-reply.+?)@.+?/i)
|
next if recipient_email.match?(/(mailer-daemon|postmaster|abuse|root|noreply|noreply.+?|no-reply|no-reply.+?)@.+?/i)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -216,7 +216,7 @@ remove whole data from index
|
||||||
url: url,
|
url: url,
|
||||||
response: response,
|
response: response,
|
||||||
)
|
)
|
||||||
Rails.logger.info "NOTICE: can't delete index: #{humanized_error}"
|
Rails.logger.warn "Can't delete index: #{humanized_error}"
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -754,10 +754,13 @@ generate url for index or document access (only for internal use)
|
||||||
|
|
||||||
def self.humanized_error(verb:, url:, payload: nil, response:)
|
def self.humanized_error(verb:, url:, payload: nil, response:)
|
||||||
prefix = "Unable to process #{verb} request to elasticsearch URL '#{url}'."
|
prefix = "Unable to process #{verb} request to elasticsearch URL '#{url}'."
|
||||||
suffix = "\n\nResponse:\n#{response.inspect}\n\nPayload:\n#{payload.inspect}"
|
suffix = "\n\nResponse:\n#{response.inspect}\n\n"
|
||||||
|
|
||||||
if payload.respond_to?(:to_json)
|
if payload.respond_to?(:to_json)
|
||||||
|
suffix += "Payload:\n#{payload.to_json}"
|
||||||
suffix += "\n\nPayload size: #{payload.to_json.bytesize / 1024 / 1024}M"
|
suffix += "\n\nPayload size: #{payload.to_json.bytesize / 1024 / 1024}M"
|
||||||
|
else
|
||||||
|
suffix += "Payload:\n#{payload.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
message = if response&.error&.match?('Connection refused')
|
message = if response&.error&.match?('Connection refused')
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Service::GeoCalendar::Zammad
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if !response.success? && response.code.to_s !~ /^40.$/
|
if !response.success? && response.code.to_s !~ /^40.$/
|
||||||
raise "ERROR: #{response.code}/#{response.body}"
|
raise "#{response.code}/#{response.body}"
|
||||||
end
|
end
|
||||||
|
|
||||||
data = response.data
|
data = response.data
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Service::GeoIp::Zammad
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if !response.success? && response.code.to_s !~ /^40.$/
|
if !response.success? && response.code.to_s !~ /^40.$/
|
||||||
raise "ERROR: #{response.code}/#{response.body}"
|
raise "#{response.code}/#{response.body}"
|
||||||
end
|
end
|
||||||
|
|
||||||
data = response.data
|
data = response.data
|
||||||
|
|
|
@ -30,7 +30,7 @@ prepares elasticsearch
|
||||||
if ENV['ES_URL'].blank?
|
if ENV['ES_URL'].blank?
|
||||||
return if !required
|
return if !required
|
||||||
|
|
||||||
raise "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
|
raise "Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
|
||||||
end
|
end
|
||||||
|
|
||||||
Setting.set('es_url', ENV['ES_URL'])
|
Setting.set('es_url', ENV['ES_URL'])
|
||||||
|
@ -46,7 +46,7 @@ prepares elasticsearch
|
||||||
ENV['ES_INDEX'] = "es_index_#{test_method_name.downcase}_#{rand_id}_#{rand(999_999_999)}"
|
ENV['ES_INDEX'] = "es_index_#{test_method_name.downcase}_#{rand_id}_#{rand(999_999_999)}"
|
||||||
end
|
end
|
||||||
if ENV['ES_INDEX'].blank?
|
if ENV['ES_INDEX'].blank?
|
||||||
raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
|
raise "Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
|
||||||
end
|
end
|
||||||
|
|
||||||
Setting.set('es_index', ENV['ES_INDEX'])
|
Setting.set('es_index', ENV['ES_INDEX'])
|
||||||
|
|
Loading…
Reference in a new issue