From ce13051d61e1d644c58c8246fc6b0eef8324dfe4 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Sat, 25 Oct 2014 14:01:21 +0100 Subject: [PATCH] eliminate guesswork with Vagrantfile errors If the Vagrantfile has some kind of error, display not only its path and the exception message, but also the originating line number and exception class. Also log the full backtrace when the error is in a provider block, just as it is done when it's outside a provider block. --- lib/vagrant/config/loader.rb | 2 ++ plugins/kernel_v2/config/vm.rb | 7 +++++++ templates/locales/en.yml | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/config/loader.rb b/lib/vagrant/config/loader.rb index 35b0d0828..2ebd339a1 100644 --- a/lib/vagrant/config/loader.rb +++ b/lib/vagrant/config/loader.rb @@ -212,6 +212,8 @@ module Vagrant # Report the generic exception raise Errors::VagrantfileLoadError, path: path, + line: e.backtrace[0].split(':')[1], + exception_class: e.class, message: e.message end end diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 155a0d62f..ed4e750fb 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -37,6 +37,8 @@ module VagrantPlugins attr_reader :provisioners def initialize + @logger = Log4r::Logger.new("vagrant::config::vm") + @base_mac = UNSET_VALUE @boot_timeout = UNSET_VALUE @box = UNSET_VALUE @@ -446,8 +448,13 @@ module VagrantPlugins config = config.merge(new_config) end rescue Exception => e + @logger.error("Vagrantfile load error: #{e.message}") + @logger.error(e.backtrace.join("\n")) + raise Vagrant::Errors::VagrantfileLoadError, path: "", + line: e.backtrace[0].split(':')[1], + exception_class: e.class, message: e.message end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index f96fb9312..acff0a687 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1200,7 +1200,8 @@ en: a syntax error. Path: %{path} - Message: %{message} + Line number: %{line} + Message: %{exception_class}: %{message} vagrantfile_syntax_error: |- There is a syntax error in the following Vagrantfile. The syntax error message is reproduced below for convenience: