Show proper syntax error for Vagrantfiles [closes GH-155]
This commit is contained in:
parent
53aaa4f264
commit
ce9ff73ea4
|
@ -9,7 +9,7 @@ begin
|
||||||
rescue Vagrant::Errors::VagrantError => e
|
rescue Vagrant::Errors::VagrantError => e
|
||||||
opts = { :_translate => false, :_prefix => false }
|
opts = { :_translate => false, :_prefix => false }
|
||||||
env.ui.error e.message, opts if e.message
|
env.ui.error e.message, opts if e.message
|
||||||
env.ui.error e.backtrace.join("\n"), opts if ENV["VAGRANT_DEBUG"] || e.show_stacktrace
|
env.ui.error e.backtrace.join("\n"), opts if ENV["VAGRANT_DEBUG"]
|
||||||
exit e.status_code if e.respond_to?(:status_code)
|
exit e.status_code if e.respond_to?(:status_code)
|
||||||
exit 999 # An error occurred with no status code defined
|
exit 999 # An error occurred with no status code defined
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,9 +54,9 @@ module Vagrant
|
||||||
if item.is_a?(String) && File.exist?(item)
|
if item.is_a?(String) && File.exist?(item)
|
||||||
begin
|
begin
|
||||||
load item
|
load item
|
||||||
rescue SyntaxError
|
rescue SyntaxError => e
|
||||||
# Report syntax errors in a nice way for Vagrantfiles
|
# Report syntax errors in a nice way for Vagrantfiles
|
||||||
raise Errors::VagrantfileSyntaxError.new(:file => item)
|
raise Errors::VagrantfileSyntaxError.new(:file => e.message)
|
||||||
end
|
end
|
||||||
elsif item.is_a?(Proc)
|
elsif item.is_a?(Proc)
|
||||||
self.class.run(&item)
|
self.class.run(&item)
|
||||||
|
|
|
@ -29,10 +29,6 @@ module Vagrant
|
||||||
define_method(:error_namespace) { namespace }
|
define_method(:error_namespace) { namespace }
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.force_stacktrace
|
|
||||||
define_method(:show_stacktrace) { true }
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize(message=nil, *args)
|
def initialize(message=nil, *args)
|
||||||
message = { :_key => message } if message && !message.is_a?(Hash)
|
message = { :_key => message } if message && !message.is_a?(Hash)
|
||||||
message = { :_key => error_key, :_namespace => error_namespace }.merge(message || {})
|
message = { :_key => error_key, :_namespace => error_namespace }.merge(message || {})
|
||||||
|
@ -50,9 +46,6 @@ module Vagrant
|
||||||
# {error_key} method but can be overridden here if needed.
|
# {error_key} method but can be overridden here if needed.
|
||||||
def error_key; nil; end
|
def error_key; nil; end
|
||||||
|
|
||||||
# Force the stacktrace to show (false by default)
|
|
||||||
def show_stacktrace; false; end
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def translate_error(opts)
|
def translate_error(opts)
|
||||||
|
@ -219,7 +212,6 @@ module Vagrant
|
||||||
class VagrantfileSyntaxError < VagrantError
|
class VagrantfileSyntaxError < VagrantError
|
||||||
status_code(41)
|
status_code(41)
|
||||||
error_key(:vagrantfile_syntax_error)
|
error_key(:vagrantfile_syntax_error)
|
||||||
force_stacktrace
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class VirtualBoxInvalidOSE < VagrantError
|
class VirtualBoxInvalidOSE < VagrantError
|
||||||
|
|
|
@ -57,11 +57,10 @@ en:
|
||||||
A VM system type must be specified! This is done via the `config.vm.system`
|
A VM system type must be specified! This is done via the `config.vm.system`
|
||||||
configuration value. Please read the documentation online for more information.
|
configuration value. Please read the documentation online for more information.
|
||||||
vagrantfile_syntax_error: |-
|
vagrantfile_syntax_error: |-
|
||||||
There is a syntax error in the following Vagrantfile. The stack trace
|
There is a syntax error in the following Vagrantfile. The syntax error
|
||||||
is also printed below for convenience.
|
message is reproduced below for convenience:
|
||||||
|
|
||||||
%{file}
|
%{file}
|
||||||
|
|
||||||
virtualbox_invalid_ose: |-
|
virtualbox_invalid_ose: |-
|
||||||
Vagrant has detected you're using an OSE ("Open Source Edition") of VirtualBox.
|
Vagrant has detected you're using an OSE ("Open Source Edition") of VirtualBox.
|
||||||
Vagrant currently doesn't support any of the OSE editions due to slight API
|
Vagrant currently doesn't support any of the OSE editions due to slight API
|
||||||
|
|
|
@ -39,13 +39,4 @@ class ErrorsTest < Test::Unit::TestCase
|
||||||
klass = Class.new(@super) { error_key(:test_key_with_interpolation) }
|
klass = Class.new(@super) { error_key(:test_key_with_interpolation) }
|
||||||
assert_equal I18n.t("vagrant.test.errors.test_key_with_interpolation", :key => "yo"), klass.new(:key => "yo").message
|
assert_equal I18n.t("vagrant.test.errors.test_key_with_interpolation", :key => "yo"), klass.new(:key => "yo").message
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not force stacktrace show by default" do
|
|
||||||
assert !@super.new.show_stacktrace
|
|
||||||
end
|
|
||||||
|
|
||||||
should "force stacktrace to show if enabled" do
|
|
||||||
klass = Class.new(@super) { force_stacktrace }
|
|
||||||
assert klass.new.show_stacktrace
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue