From ce9ff73ea4bfc88aa99fe7898d208b69cdfb0d79 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 4 Sep 2010 14:33:53 -0700 Subject: [PATCH] Show proper syntax error for Vagrantfiles [closes GH-155] --- bin/vagrant | 2 +- lib/vagrant/config.rb | 4 ++-- lib/vagrant/errors.rb | 8 -------- templates/locales/en.yml | 5 ++--- test/vagrant/errors_test.rb | 9 --------- 5 files changed, 5 insertions(+), 23 deletions(-) diff --git a/bin/vagrant b/bin/vagrant index 43df179b6..e07c42423 100755 --- a/bin/vagrant +++ b/bin/vagrant @@ -9,7 +9,7 @@ begin rescue Vagrant::Errors::VagrantError => e opts = { :_translate => false, :_prefix => false } 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 999 # An error occurred with no status code defined end diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index 0dd87d57f..b01e2d397 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -54,9 +54,9 @@ module Vagrant if item.is_a?(String) && File.exist?(item) begin load item - rescue SyntaxError + rescue SyntaxError => e # Report syntax errors in a nice way for Vagrantfiles - raise Errors::VagrantfileSyntaxError.new(:file => item) + raise Errors::VagrantfileSyntaxError.new(:file => e.message) end elsif item.is_a?(Proc) self.class.run(&item) diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 50a45c123..ed0f9c8de 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -29,10 +29,6 @@ module Vagrant define_method(:error_namespace) { namespace } end - def self.force_stacktrace - define_method(:show_stacktrace) { true } - end - def initialize(message=nil, *args) message = { :_key => message } if message && !message.is_a?(Hash) 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. def error_key; nil; end - # Force the stacktrace to show (false by default) - def show_stacktrace; false; end - protected def translate_error(opts) @@ -219,7 +212,6 @@ module Vagrant class VagrantfileSyntaxError < VagrantError status_code(41) error_key(:vagrantfile_syntax_error) - force_stacktrace end class VirtualBoxInvalidOSE < VagrantError diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 416d63fbf..743b45045 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -57,11 +57,10 @@ en: 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. vagrantfile_syntax_error: |- - There is a syntax error in the following Vagrantfile. The stack trace - is also printed below for convenience. + There is a syntax error in the following Vagrantfile. The syntax error + message is reproduced below for convenience: %{file} - virtualbox_invalid_ose: |- 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 diff --git a/test/vagrant/errors_test.rb b/test/vagrant/errors_test.rb index a482e7b4f..ab885df4f 100644 --- a/test/vagrant/errors_test.rb +++ b/test/vagrant/errors_test.rb @@ -39,13 +39,4 @@ class ErrorsTest < Test::Unit::TestCase 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 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