Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
None
-
Windows 2012r2 x64
PowerShell 4
-
1
-
Windows 2016-04-20, Windows 2016-05-04, Windows 2016-05-18, Windows 2016-06-01, Windows 2016-06-15
-
Reviewed
-
1 - 1-5% of Customers
-
2 - Annoyance
-
3 - $$$$
Description
This is some strange behavior.
With puppetlabs-powershell v1.0.5, I'm seeing that if I have a templated script, and I wrap a try catch around it, it no longer executes the script.
Create a module.
In manifests init.pp, do the following:
exec { 'test_try_catch':
|
command => template('yourmodule/test.ps1.erb'),
|
provider => powershell,
|
logoutput=> true,
|
}
|
In templates folder, add a file called test.ps1.erb:
Write-Host "Should log this message."
|
|
try {
|
# make it long running
|
Write-Host "Sleeping for 10 seconds."
|
Start-Sleep 10
|
|
# intentionally throw an error:
|
$filePath = Join-Path $nonExistent 'scripts'
|
|
} catch {
|
Write-Host "$($_.Exception.Message)"
|
exit 1
|
}
|
Watch it run almost in 1 second.
Now comment out or remove the try/catch in the erb:
Write-Host "Should log this message."
|
|
#try {
|
# make it long running
|
Write-Host "Sleeping for 10 seconds."
|
Start-Sleep 10
|
|
# intentionally throw an error:
|
$filePath = Join-Path $nonExistent 'scripts'
|
|
#} catch {
|
# Write-Host "$($_.Exception.Message)"
|
# exit 1
|
#}
|
Note that it runs and throws an error now.
You can also attempt to add $ErrorActionPreference = 'Stop' to the script. Any ideas on this one?
Attachments
Issue Links
- is blocked by
-
MODULES-2962 Extend reusing PowerShell session improvements to PowerShell Module
-
- Resolved
-
- relates to
-
MODULES-3285 Remove beaker-rspec from Powershell Module test suite
-
- Resolved
-
-
MODULES-1996 PowerShell module doesn't recognize elseif
-
- Closed
-
-
MODULES-2774 Powershell module continue to run on error
-
- Closed
-
- links to
- mentioned in
-
Page Loading...