Exception: Hglib::CommandError
Overview
Specialized exception for handling errors returned by the command server.
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
The command that resulted in an error.
-
#details ⇒ Object
readonly
Additional details of the error.
-
#messages ⇒ Object
readonly
The Array of error messages generated by the command.
Instance Method Summary collapse
-
#initialize(command, *messages, details: nil) ⇒ CommandError
constructor
Create a new CommandError with the given
args. -
#message ⇒ Object
Overridden to format multi-message errors in a more-readable way.
-
#multiple? ⇒ Boolean
Returns
trueif the command resulted in more than one error message.
Constructor Details
#initialize(command, *messages, details: nil) ⇒ CommandError
Create a new CommandError with the given args.
37 38 39 40 41 42 |
# File 'lib/hglib.rb', line 37 def initialize( command, *, details: nil ) @command = command @messages = .flatten.map( &:chomp ) @messages << "error in hg command" if @messages.empty? @details = details end |
Instance Attribute Details
#command ⇒ Object (readonly)
The command that resulted in an error
47 48 49 |
# File 'lib/hglib.rb', line 47 def command @command end |
#details ⇒ Object (readonly)
Additional details of the error
55 56 57 |
# File 'lib/hglib.rb', line 55 def details @details end |
#messages ⇒ Object (readonly)
The Array of error messages generated by the command
51 52 53 |
# File 'lib/hglib.rb', line 51 def @messages end |
Instance Method Details
#message ⇒ Object
Overridden to format multi-message errors in a more-readable way.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/hglib.rb', line 65 def msg = String.new( encoding: 'utf-8' ) msg << "`%s`:" % [ self.command ] if self.multiple? self..each do |errmsg| msg << "\n" << ' - ' << errmsg end msg << "\n" else msg << ' ' << self..first end msg << "\n" << self.details if self.details return msg end |
#multiple? ⇒ Boolean
Returns true if the command resulted in more than one error message.
59 60 61 |
# File 'lib/hglib.rb', line 59 def multiple? return self..length > 1 end |