bolt-modules/boltlib/lib/puppet/functions/fail_plan.rb in bolt-1.12.0 vs bolt-modules/boltlib/lib/puppet/functions/fail_plan.rb in bolt-1.13.0
- old
+ new
@@ -4,10 +4,12 @@
# Raises a Bolt::PlanFailure exception to signal to callers that the plan failed.
#
# Plan authors should call this function when their plan is not successful. The
# error may then be caught by another plans run_plan function or in bolt itself
+#
+# **NOTE:** Not available in apply block
Puppet::Functions.create_function(:fail_plan) do
# Fail a plan, generating an exception from the parameters.
# @param msg An error message.
# @param kind An easily matchable error kind.
# @param details Machine-parseable details about the error.
@@ -30,9 +32,14 @@
dispatch :from_error do
param 'Error', :error
end
def from_args(msg, kind = nil, details = nil, issue_code = nil)
+ unless Puppet[:tasks]
+ raise Puppet::ParseErrorWithIssue
+ .from_issue_and_stack(Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, action: 'fail_plan')
+ end
+
executor = Puppet.lookup(:bolt_executor) { nil }
executor&.report_function_call('fail_plan')
raise Bolt::PlanFailure.new(msg, kind || 'bolt/plan-failure', details, issue_code)
end