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.
This commit is contained in:
Seth Vargo 2015-05-31 18:32:21 -07:00
parent ce13051d61
commit 6b2ef13785
2 changed files with 14 additions and 2 deletions

View File

@ -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

View File

@ -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: "<provider config: #{name}>",
line: e.backtrace[0].split(':')[1],
line: line,
exception_class: e.class,
message: e.message
end