From 0054c5aae6ee9f7a0b54b867a20e33fc1f104a53 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 4 Apr 2018 11:31:59 -0700 Subject: [PATCH] Raise error if incomplete trigger block is defined --- lib/vagrant/errors.rb | 4 ++++ plugins/kernel_v2/config/trigger.rb | 6 ++++++ templates/locales/en.yml | 3 +++ 3 files changed, 13 insertions(+) diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index a1b3df969..bd9e67c26 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -780,6 +780,10 @@ module Vagrant error_key(:triggers_guest_not_running) end + class TriggersNoBlockGiven < VagrantError + error_key(:triggers_no_block_given) + end + class TriggersNoStageGiven < VagrantError error_key(:triggers_no_stage_given) end diff --git a/plugins/kernel_v2/config/trigger.rb b/plugins/kernel_v2/config/trigger.rb index 1945ed7a3..546901aee 100644 --- a/plugins/kernel_v2/config/trigger.rb +++ b/plugins/kernel_v2/config/trigger.rb @@ -49,6 +49,9 @@ module VagrantPlugins # so the last element should be the "config block" # and the rest are commands for the trigger blk = command.pop + elsif !block_given? + raise Vagrant::Errors::TriggersNoBlockGiven, + command: command end command.each do |cmd| @@ -71,6 +74,9 @@ module VagrantPlugins # so the last element should be the "config block" # and the rest are commands for the trigger blk = command.pop + elsif !block_given? + raise Vagrant::Errors::TriggersNoBlockGiven, + command: command end command.each do |cmd| diff --git a/templates/locales/en.yml b/templates/locales/en.yml index e20091fce..9d7dac8a4 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1414,6 +1414,9 @@ en: Trigger run failed triggers_guest_not_running: |- Could not run remote script on %{machine_name} because its state is %{state} + triggers_no_block_given: |- + There was an error parsing the Vagrantfile: + No config was given for the trigger(s) %{command}. triggers_no_stage_given: |- The incorrect stage was given to the trigger plugin: Guest: %{guest_name}