Add error text to exception when an error was logged
This commit is contained in:
parent
bd4310a080
commit
ee81807f49
@ -9,7 +9,8 @@ module PgLdapSync
|
||||
class ApplicationExit < RuntimeError
|
||||
attr_reader :exitcode
|
||||
|
||||
def initialize(exitcode)
|
||||
def initialize(exitcode, error=nil)
|
||||
super(error)
|
||||
@exitcode = exitcode
|
||||
end
|
||||
end
|
||||
|
@ -384,14 +384,14 @@ class Application
|
||||
|
||||
# Determine exitcode
|
||||
if log.had_errors?
|
||||
raise ErrorExit, 1
|
||||
raise ErrorExit.new(1, log.first_error)
|
||||
end
|
||||
end
|
||||
|
||||
def self.run(argv)
|
||||
s = self.new
|
||||
s.config_fname = '/etc/pg_ldap_sync.yaml'
|
||||
s.log = Logger.new($stdout, @error_counters)
|
||||
s.log = Logger.new($stdout)
|
||||
s.log.level = Logger::ERROR
|
||||
|
||||
OptionParser.new do |opts|
|
||||
|
@ -2,23 +2,27 @@ require 'logger'
|
||||
|
||||
module PgLdapSync
|
||||
class Logger < ::Logger
|
||||
def initialize(io, counters)
|
||||
def initialize(io)
|
||||
super(io)
|
||||
@counters = {}
|
||||
end
|
||||
|
||||
def add(severity, *args)
|
||||
@counters[severity] ||= 0
|
||||
@counters[severity] += 1
|
||||
def add(severity, *args, &block)
|
||||
return unless [Logger::FATAL, Logger::ERROR].include?(severity)
|
||||
@counters[severity] ||= block ? block.call : args.first
|
||||
super
|
||||
end
|
||||
|
||||
def had_logged?(severity)
|
||||
@counters[severity] && @counters[severity] > 0
|
||||
!!@counters[severity]
|
||||
end
|
||||
|
||||
def had_errors?
|
||||
had_logged?(Logger::FATAL) || had_logged?(Logger::ERROR)
|
||||
end
|
||||
|
||||
def first_error
|
||||
@counters[Logger::FATAL] || @counters[Logger::ERROR]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user