Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to throw on failure #1908

Merged
merged 2 commits into from
Apr 17, 2021
Merged

Add option to throw on failure #1908

merged 2 commits into from
Apr 17, 2021

Conversation

nohwnd
Copy link
Member

@nohwnd nohwnd commented Apr 17, 2021

Throw on failure when enabled. If you want to process the result for some reason after catching the exception, you need to use

$result = try { Invoke-Pester ... } catch { $err = $_ }

And not

try { $result = Invoke-Pester ... } catch { }

Because then the assignment will never happen and $result will be null.

But in such case it is better to just not enable the throwing and throw yourself based on the .Result

Fix #1843

Throw on failure when enabled. If you want to process the result for some reason after catching the exception, you need to use `$result = try { Invoke-Pester ... } catch { $err = $_ }`, not `try { $result = Invoke-Pester ... } catch { }` because then the assignment will never happen and `$result` will be null.
@nohwnd
Copy link
Member Author

nohwnd commented Apr 17, 2021

@JustinGrote I think you also asked for this somewhere.

tst/Pester.RSpec.ts.ps1 Outdated Show resolved Hide resolved
@nohwnd nohwnd merged commit 755543f into v5.0 Apr 17, 2021
@nohwnd nohwnd deleted the throw-on-failure branch April 17, 2021 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'-ErrorAction Stop' not respected by 'Invoke-Pester'
1 participant