From a22acba467191da6d683bf96f690a48995bd1c5b Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 10 Sep 2019 13:27:23 -0700 Subject: [PATCH] Simplify line and path checks for exception handling in config loading --- lib/vagrant/config/loader.rb | 9 ++------- plugins/kernel_v2/config/vm.rb | 8 +------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/lib/vagrant/config/loader.rb b/lib/vagrant/config/loader.rb index 2c7e8b22e..6c58092b3 100644 --- a/lib/vagrant/config/loader.rb +++ b/lib/vagrant/config/loader.rb @@ -131,13 +131,8 @@ module Vagrant path = "(unknown)" if e.backtrace && e.backtrace[0] backtrace_tokens = e.backtrace[0].split(":") - if Vagrant::Util::Platform.windows? - # path is split into two tokens on windows for some reason... - # where 0th is drive letter, 1st is path - path = backtrace_tokens[0] + ":" + backtrace_tokens[1] - else - path = backtrace_tokens[0] - end + path = e.backtrace.first.slice(0, e.backtrace.first.rindex(':')).rpartition(':').first + backtrace_tokens.each do |part| if part =~ /\d+/ line = part.to_i diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 64a72c821..6339d3e4b 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -509,13 +509,7 @@ module VagrantPlugins line = "(unknown)" if e.backtrace && e.backtrace[0] - if Vagrant::Util::Platform.windows? - # path is split into two tokens on windows for some reason... - # where 0th is drive letter, 1st is path, so line number is token 2 - line = e.backtrace[0].split(":")[2] - else - line = e.backtrace[0].split(":")[1] - end + line = e.backtrace.first.slice(0, e.backtrace.first.rindex(':')).rpartition(':').last end raise Vagrant::Errors::VagrantfileLoadError,