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("Vagrantfile load error: #{e.message}")
@logger.error(e.backtrace.join("\n")) @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 # Report the generic exception
raise Errors::VagrantfileLoadError, raise Errors::VagrantfileLoadError,
path: path, path: path,
line: e.backtrace[0].split(':')[1], line: line,
exception_class: e.class, exception_class: e.class,
message: e.message message: e.message
end end

View File

@ -449,11 +449,18 @@ module VagrantPlugins
end end
rescue Exception => e rescue Exception => e
@logger.error("Vagrantfile load error: #{e.message}") @logger.error("Vagrantfile load error: #{e.message}")
@logger.error(e.inspect)
@logger.error(e.message)
@logger.error(e.backtrace.join("\n")) @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, raise Vagrant::Errors::VagrantfileLoadError,
path: "<provider config: #{name}>", path: "<provider config: #{name}>",
line: e.backtrace[0].split(':')[1], line: line,
exception_class: e.class, exception_class: e.class,
message: e.message message: e.message
end end