From ccf99d8c0cecc50438b9e5c61e8052d55f6fc871 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 6 Sep 2019 13:37:38 -0700 Subject: [PATCH 1/4] Fixes #11022: Show proper path & letter drive on exceptions for windows Prior to this commit, vagrant was not grabbing all of the tokens on Windows for showing the full drive because the ruby api for it behaves differenly on windows compared to other platforms. This commit changes that by ensuring the letter drive is attached to the path when showing an exception. --- lib/vagrant/config/loader.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/config/loader.rb b/lib/vagrant/config/loader.rb index 64d4f404a..2c7e8b22e 100644 --- a/lib/vagrant/config/loader.rb +++ b/lib/vagrant/config/loader.rb @@ -2,6 +2,8 @@ require "pathname" require "log4r" +require "vagrant/util/platform" + module Vagrant module Config # This class is responsible for loading Vagrant configuration, @@ -129,7 +131,13 @@ module Vagrant path = "(unknown)" if e.backtrace && e.backtrace[0] backtrace_tokens = e.backtrace[0].split(":") - path = backtrace_tokens[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 + path = backtrace_tokens[0] + ":" + backtrace_tokens[1] + else + path = backtrace_tokens[0] + end backtrace_tokens.each do |part| if part =~ /\d+/ line = part.to_i From 09a37e0767483976b23fc9b084256065d05a8df9 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 6 Sep 2019 13:52:52 -0700 Subject: [PATCH 2/4] Fixes #11022: Ensure correct line is used for windows exceptions Prior to this commit, if there was a config error inside a provider block, Vagrant wouldn't grab the right backtrace token on windows since the api is different for ruby on Windows compared to all other platforms. This commit ensures that the proper line number is chosen so the error message is correct. --- plugins/kernel_v2/config/vm.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 3169b0552..64a72c821 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -509,7 +509,13 @@ module VagrantPlugins line = "(unknown)" if e.backtrace && e.backtrace[0] - line = e.backtrace[0].split(":")[1] + 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 end raise Vagrant::Errors::VagrantfileLoadError, From a22acba467191da6d683bf96f690a48995bd1c5b Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 10 Sep 2019 13:27:23 -0700 Subject: [PATCH 3/4] 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, From ace67ccdebb98022f00a6e5f0120fe648524a9a5 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 10 Sep 2019 13:28:37 -0700 Subject: [PATCH 4/4] Remove platform require since it is no longer required in file --- lib/vagrant/config/loader.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/vagrant/config/loader.rb b/lib/vagrant/config/loader.rb index 6c58092b3..7588d7751 100644 --- a/lib/vagrant/config/loader.rb +++ b/lib/vagrant/config/loader.rb @@ -2,8 +2,6 @@ require "pathname" require "log4r" -require "vagrant/util/platform" - module Vagrant module Config # This class is responsible for loading Vagrant configuration, @@ -132,7 +130,6 @@ module Vagrant if e.backtrace && e.backtrace[0] backtrace_tokens = e.backtrace[0].split(":") path = e.backtrace.first.slice(0, e.backtrace.first.rindex(':')).rpartition(':').first - backtrace_tokens.each do |part| if part =~ /\d+/ line = part.to_i