Exception: P4Error

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/p4_error.rb

Overview

Any error we get from the Perforce server is generally encapsulated in a P4Error, which allows us to get some basic diagnostic information from the Perforce server out to the user.

Direct Known Subclasses

HelixSync::LockFailed, HelixSync::SubmitFailed

Constant Summary

ERROR_CODE_BASE =

All error codes must be greater than this number.

15_360

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (P4Error) initialize(code, severity, text)

Returns a new instance of P4Error



32
33
34
35
36
# File 'lib/p4_error.rb', line 32

def initialize(code, severity, text)
  @message_code     = code
  @message_severity = severity
  @message_text     = text
end

Instance Attribute Details

- (Object) message_code

Note: We use 15_361 for 'unhandled' ruby errors



16
17
18
# File 'lib/p4_error.rb', line 16

def message_code
  @message_code
end

- (Object) message_severity

Note: We use 15_361 for 'unhandled' ruby errors



16
17
18
# File 'lib/p4_error.rb', line 16

def message_severity
  @message_severity
end

- (Object) message_text

Note: We use 15_361 for 'unhandled' ruby errors



16
17
18
# File 'lib/p4_error.rb', line 16

def message_text
  @message_text
end

Class Method Details

+ (Object) default_error(message_text)

Class method to create a valid P4Error object from a simple string. Used when we get errors for which no P4::Message object is available.



21
22
23
24
25
# File 'lib/p4_error.rb', line 21

def self.default_error(message_text)
  P4Error.new(ERROR_CODE_BASE,
              P4::E_FAILED,
              message_text)
end

+ (Boolean) error?(p4, severity: P4::E_FAILED)

Returns true if there's an error

Returns:

  • (Boolean)


28
29
30
# File 'lib/p4_error.rb', line 28

def self.error?(p4, severity: P4::E_FAILED)
  return p4.messages && p4.messages.any? {|m| m.severity >= severity}
end

Instance Method Details

- (Boolean) system_error?

Returns true if the exception is truly a system problem.

Returns:

  • (Boolean)


45
46
47
# File 'lib/p4_error.rb', line 45

def system_error?
  return @message_severity == P4::E_FATAL
end

- (Object) to_s



49
50
51
# File 'lib/p4_error.rb', line 49

def to_s
  @message_text
end

- (Boolean) user_error?

Returns true if the exception should actually be considered a user error instead of a system exception.

Returns:

  • (Boolean)


40
41
42
# File 'lib/p4_error.rb', line 40

def user_error?
  return @message_severity == P4::E_FAILED
end