Specialized exception for handling errors returned by the command server.
The command that resulted in an error
Additional details of the error
The Array of error messages generated by the command
Create a new CommandError
with the given args
.
# File lib/hglib.rb, line 36
def initialize( command, *messages, details: nil )
@command = command
@messages = messages.flatten.map( &:chomp )
@messages << "error in hg command" if @messages.empty?
@details = details
end
Overridden to format multi-message errors in a more-readable way.
# File lib/hglib.rb, line 64
def message
msg = String.new( encoding: 'utf-8' )
msg << "`%s`:" % [ self.command ]
if self.multiple?
self.messages.each do |errmsg|
msg << "\n" << ' - ' << errmsg
end
msg << "\n"
else
msg << ' ' << self.messages.first
end
msg << "\n" << self.details if self.details
return msg
end
Returns true
if the command resulted in more than one error message.
# File lib/hglib.rb, line 58
def multiple?
return self.messages.length > 1
end