Closed tcables closed 6 years ago
Fully agree with you @tcables. Spent quite a time to find out how I can handle errors. So I've created #38 to help others.
But, I want to create an option ThrowIfErrorOccured
in PowershellSettings
. And method StartPowershellScript will throw exception if it's true.
Would @SharpeRAD accept such PR?
Throwing errors should be the default action, so no need in an extra setting.
Submit a PR that effectively duplicates this (L303 - L310) for "ErrorRecord" as well as Exceptions.
@SharpeRAD So, it means that there is a bug. Code you pointed out will not work for errors (not exceptions).
var exceptions = _pipelineResults.Where(result => result.BaseObject is Exception)
.Select(e => e.BaseObject as Exception).ToArray();
Because in case of errors in scripts result.BaseObject
will be ErrorRecord not the Exception
type. I've checked that yesterday.
So we either should introduce new property or it will break builds someone who do not care about errors (not exceptions).
This thread is talking about being consistent with Powershell and throwing exceptions for errors. I pointed you to those lines as that's the area you would need to change.
Can you name an instance where you would not throw on an error? EG: Cake only has a task method "OnError" it doesn't have a method "OnException" 😄
Add a setting to be safe, as I shouldn't base everything on my own preference.
@SharpeRAD Actually for me always throwing exceptions is also preferred choice. But I am afraid that it will break builds for guys for whom errors is not critical right now
So we have 3 options:
1) Always throw exceptions on errors
2) Throw exception on errors if ThrowIfErrorOccured
option is set.
3) Throw by default but make it optional via option SwallowErrorsInsteadThrow
1st and 3rd options may break builds. (we need to make a statement about it in release notes). but in 3rd option at least anyone can fix it via passing additional parameter. (Names are subject for discussion)
Can you probably make some mention in gitter chat to make a quick poll here via smiles. Heart - option 1 Laugh - option 2 Hooray - option 3
Resolved in #46
Hi, thanks for making such a useful addon for Cake!
If a simple command is run, and it fails, the error is not recognized as an error by the Cake Task:
eg, call "Import-Module" with no parameters will throw an exception in powershell:
Cake setup:
Output:
Even adding ErrorAction Stop will not aid:
but if you use 'throw' directly from a powershell script it will work as expected:
cake:
output:
But I should not have to have to wrap all of my calls in a try-catch-throw-rethrow:
Thanks!