core: refactor error initialization logic
/cc @tmatilai - This includes a test case for the symbol stuff, should be okay now.
This commit is contained in:
parent
481924c46d
commit
7631a38601
|
@ -59,11 +59,14 @@ module Vagrant
|
||||||
define_method(:error_namespace) { namespace }
|
define_method(:error_namespace) { namespace }
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(message=nil, *args)
|
def initialize(*args)
|
||||||
|
key = args.shift if args.first.is_a?(Symbol)
|
||||||
|
message = args.shift if args.first.is_a?(Hash)
|
||||||
message ||= {}
|
message ||= {}
|
||||||
@extra_data = message.dup
|
@extra_data = message.dup
|
||||||
message = { :_key => message } if message && !message.is_a?(Hash)
|
message[:_key] ||= error_key
|
||||||
message = { :_key => error_key, :_namespace => error_namespace }.merge(message || {})
|
message[:_namespace] ||= error_namespace
|
||||||
|
message[:_key] = key if key
|
||||||
|
|
||||||
if message[:_key]
|
if message[:_key]
|
||||||
message = translate_error(message)
|
message = translate_error(message)
|
||||||
|
@ -71,7 +74,7 @@ module Vagrant
|
||||||
message = error_message
|
message = error_message
|
||||||
end
|
end
|
||||||
|
|
||||||
super
|
super(message)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The error message for this error. This is used if no error_key
|
# The error message for this error. This is used if no error_key
|
||||||
|
|
|
@ -708,7 +708,6 @@ en:
|
||||||
The synced folder type '%{type}' is reporting as unusable for
|
The synced folder type '%{type}' is reporting as unusable for
|
||||||
your current setup. Please verify you have all the proper
|
your current setup. Please verify you have all the proper
|
||||||
prerequisites for using this shared folder type and try again.
|
prerequisites for using this shared folder type and try again.
|
||||||
test_key: "test value"
|
|
||||||
ui_expects_tty: |-
|
ui_expects_tty: |-
|
||||||
Vagrant is attempting to interface with the UI in a way that requires
|
Vagrant is attempting to interface with the UI in a way that requires
|
||||||
a TTY. Most actions in Vagrant that require a TTY have configuration
|
a TTY. Most actions in Vagrant that require a TTY have configuration
|
||||||
|
@ -816,6 +815,7 @@ en:
|
||||||
vm_not_running: |-
|
vm_not_running: |-
|
||||||
VM must be running to open SSH connection. Run `vagrant up`
|
VM must be running to open SSH connection. Run `vagrant up`
|
||||||
to start the virtual machine.
|
to start the virtual machine.
|
||||||
|
test_key: "test value"
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# Translations for config validation errors
|
# Translations for config validation errors
|
||||||
|
|
|
@ -43,5 +43,11 @@ describe Vagrant::Errors::VagrantError do
|
||||||
expect(subject.extra_data).to have_key(:data)
|
expect(subject.extra_data).to have_key(:data)
|
||||||
expect(subject.extra_data[:data]).to eql("yep")
|
expect(subject.extra_data[:data]).to eql("yep")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should use a symbol initializer as a key" do
|
||||||
|
subject = klass.new(:test_key)
|
||||||
|
expect(subject.extra_data).to be_empty
|
||||||
|
expect(subject.to_s).to eql("test value")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue