summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Murawski <steven.murawski@gmail.com>2015-09-03 16:36:44 -0500
committerSteven Murawski <steven.murawski@gmail.com>2015-09-04 10:02:30 -0500
commit51849a3042aa0de52da448ff1bd261e84a96bef0 (patch)
tree4ae280a6633eecc9fa02a664f0805c5278169812
parente57281eb4169e93d54ad0db26f91e5c3fc683acf (diff)
downloadchef-smurawski/fix_powershell_validation.tar.gz
Put validation in a function with different exit codesmurawski/fix_powershell_validation
-rw-r--r--lib/chef/provider/powershell_script.rb9
1 files 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