diff options
author | Steven Murawski <steven.murawski@gmail.com> | 2015-09-03 16:36:44 -0500 |
---|---|---|
committer | Steven Murawski <steven.murawski@gmail.com> | 2015-09-04 10:02:30 -0500 |
commit | 51849a3042aa0de52da448ff1bd261e84a96bef0 (patch) | |
tree | 4ae280a6633eecc9fa02a664f0805c5278169812 | |
parent | e57281eb4169e93d54ad0db26f91e5c3fc683acf (diff) | |
download | chef-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.rb | 9 |
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 |