Exception: Hglib::CommandError

Inherits:
Error
  • Object
show all
Defined in:
lib/hglib.rb

Overview

Specialized exception for handling errors returned by the command server.

Instance Attribute Summary collapse

Instance Method Summary collapse

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, *messages, details: nil )
	@command = command
	@messages = messages.flatten.map( &:chomp )
	@messages << "error in hg command" if @messages.empty?
	@details = details
end

Instance Attribute Details

#commandObject (readonly)

The command that resulted in an error



47
48
49
# File 'lib/hglib.rb', line 47

def command
  @command
end

#detailsObject (readonly)

Additional details of the error



55
56
57
# File 'lib/hglib.rb', line 55

def details
  @details
end

#messagesObject (readonly)

The Array of error messages generated by the command



51
52
53
# File 'lib/hglib.rb', line 51

def messages
  @messages
end

Instance Method Details

#messageObject

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 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

#multiple?Boolean

Returns true if the command resulted in more than one error message.

Returns:

  • (Boolean)


59
60
61
# File 'lib/hglib.rb', line 59

def multiple?
	return self.messages.length > 1
end