From 51849a3042aa0de52da448ff1bd261e84a96bef0 Mon Sep 17 00:00:00 2001 From: Steven Murawski Date: Thu, 3 Sep 2015 16:36:44 -0500 Subject: Put validation in a function with different exit code --- lib/chef/provider/powershell_script.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb index 6418075b22..0cff353ea7 100644 --- a/lib/chef/provider/powershell_script.rb +++ b/lib/chef/provider/powershell_script.rb @@ -104,15 +104,20 @@ $global:lastcmdlet = $null # Create a scriptblock with the user's code # This will validate the syntax of the PowerShell provided -$UserScriptBlock = $ExecutionContext.InvokeCommand.NewScriptBlock(@' +function New-UserScriptBlock { + try { + $ExecutionContext.InvokeCommand.NewScriptBlock(@' #{@new_resource.code} # This assignment doesn't affect the block's return value $global:lastcmdlet = $? '@) + } + catch {write-error ($_.Exception.Message);exit 5} +} # Execute the user's code in a script block -- -$chefscriptresult = $UserScriptBlock.invokereturnasis() +$chefscriptresult = (New-UserScriptBlock).invokereturnasis() # Assume failure status of 1 -- success cases # will have to override this -- cgit v1.2.1