From 6b2ef13785d2daccd6fa427a538a5fdd48322763 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 31 May 2015 18:32:21 -0700 Subject: [PATCH] Be more defensive when trying to get the line number Since this is the last line of defense before raising an error, we want to make sure we don't cause an error while trying to render the error. --- lib/vagrant/config/loader.rb | 7 ++++++- plugins/kernel_v2/config/vm.rb | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/config/loader.rb b/lib/vagrant/config/loader.rb index 2ebd339a1..e3f80a579 100644 --- a/lib/vagrant/config/loader.rb +++ b/lib/vagrant/config/loader.rb @@ -209,10 +209,15 @@ module Vagrant @logger.error("Vagrantfile load error: #{e.message}") @logger.error(e.backtrace.join("\n")) + line = "(unknown)" + if e.backtrace && e.backtrace[0] + line = e.backtrace[0].split(":")[1] + end + # Report the generic exception raise Errors::VagrantfileLoadError, path: path, - line: e.backtrace[0].split(':')[1], + line: line, exception_class: e.class, message: e.message end diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index ed4e750fb..294a63e19 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -449,11 +449,18 @@ module VagrantPlugins end rescue Exception => e @logger.error("Vagrantfile load error: #{e.message}") + @logger.error(e.inspect) + @logger.error(e.message) @logger.error(e.backtrace.join("\n")) + line = "(unknown)" + if e.backtrace && e.backtrace[0] + line = e.backtrace[0].split(":")[1] + end + raise Vagrant::Errors::VagrantfileLoadError, path: "", - line: e.backtrace[0].split(':')[1], + line: line, exception_class: e.class, message: e.message end