# vim:ts=2:sw=2:et:si:ai: # The API sends back messages via the p4.messages attribute if there was an # error with the last command. We will often convert that to this exception, # which will be formatted into JSON. require 'P4' # 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. class P4Error < RuntimeError # All error codes must be greater than this number. ERROR_CODE_BASE = 15_360 # Note: We use 15_361 for 'unhandled' ruby errors attr_accessor :message_code, :message_severity, :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. def self.default_error(message_text) P4Error.new(ERROR_CODE_BASE, P4::E_FAILED, message_text) end def initialize(code, severity, text) @message_code = code @message_severity = severity @message_text = text end def to_s @message_text end end