diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index fc30dfe1a..8654ac752 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -43,6 +43,9 @@ module Vagrant # error code, and the error key is used as a default message from # I18n. class VagrantError < StandardError + # This is extra data passed into the message for translation. + attr_accessor :extra_data + def self.error_key(key=nil, namespace=nil) define_method(:error_key) { key } error_namespace(namespace) if namespace @@ -57,6 +60,8 @@ module Vagrant end def initialize(message=nil, *args) + message ||= {} + @extra_data = message.dup message = { :_key => message } if message && !message.is_a?(Hash) message = { :_key => error_key, :_namespace => error_namespace }.merge(message || {}) diff --git a/test/unit/vagrant/errors_test.rb b/test/unit/vagrant/errors_test.rb index 66a2d1ea7..3c00b39c9 100644 --- a/test/unit/vagrant/errors_test.rb +++ b/test/unit/vagrant/errors_test.rb @@ -32,10 +32,16 @@ describe Vagrant::Errors::VagrantError do end end - subject { klass.new } + subject { klass.new(data: "yep") } it "should use the translation for the message" do subject.to_s.should == "foo" end + + it "should expose translation keys to the user" do + expect(subject.extra_data.length).to eql(1) + expect(subject.extra_data).to have_key(:data) + expect(subject.extra_data[:data]).to eql("yep") + end end end