Hglib::

CommandError

class
Superclass
Hglib::Error

Specialized exception for handling errors returned by the command server.

Attributes

command[R]

The command that resulted in an error

details[R]

Additional details of the error

messages[R]

The Array of error messages generated by the command

Public Class Methods

anchor
new( command, *messages, details: nil )

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

Public Instance Methods

anchor
message()

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
anchor
multiple?()

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