class Vagrant::Errors::VagrantError
Main superclass of any errors in Vagrant
. This provides some convenience methods for setting the status code and error key. The status code is used by the ‘vagrant` executable as the error code, and the error key is used as a default message from I18n.
Attributes
This is extra data passed into the message for translation.
Public Class Methods
# File lib/vagrant/errors.rb, line 49 def self.error_key(key=nil, namespace=nil) define_method(:error_key) { key } error_namespace(namespace) if namespace end
# File lib/vagrant/errors.rb, line 54 def self.error_message(message) define_method(:error_message) { message } end
# File lib/vagrant/errors.rb, line 58 def self.error_namespace(namespace) define_method(:error_namespace) { namespace } end
# File lib/vagrant/errors.rb, line 62 def initialize(*args) key = args.shift if args.first.is_a?(Symbol) message = args.shift if args.first.is_a?(Hash) message ||= {} @extra_data = message.dup message[:_key] ||= error_key message[:_namespace] ||= error_namespace message[:_key] = key if key if message[:_key] message = translate_error(message) else message = error_message end super(message) end
Public Instance Methods
The key for the error message. This should be set using the {error_key} method but can be overridden here if needed.
# File lib/vagrant/errors.rb, line 91 def error_key; nil; end
The error message for this error. This is used if no error_key
is specified for a translatable error message.
# File lib/vagrant/errors.rb, line 82 def error_message; "No error message"; end
The default error namespace which is used for the error key. This can be overridden here or by calling the “error_namespace” class method.
# File lib/vagrant/errors.rb, line 87 def error_namespace; "vagrant.errors"; end
This is the exit code that should be used when exiting from this exception.
@return [Integer]
# File lib/vagrant/errors.rb, line 97 def status_code; 1; end
Protected Instance Methods
# File lib/vagrant/errors.rb, line 101 def translate_error(opts) return nil if !opts[:_key] I18n.t("#{opts[:_namespace]}.#{opts[:_key]}", **opts) end