Discussion: Get-ChildException approach to supporting assertion on child exceptions#28
Discussion: Get-ChildException approach to supporting assertion on child exceptions#28alx9r wants to merge 1 commit intonohwnd:masterfrom
Conversation
implement Get-ChildException export Get-ChildException return [ErrorRecord] instead of [scriptblock] from Assert-Throw
|
One thing that bothers me is that I don't see any benefit in using the You are right about outputting the scriptblock, that does not make sense. Outputting the error is much better option |
Some exceptions have both an
Can you elaborate on what you mean by "PowerShell scripters"? |
|
Yes but what would the cmdlet without the I mean that in PowerShell we don't often come across nested structures that are simple to flatten (like $e.InnerException.InnerException.InnerException.InnerException). |
This PR demonstrates one way of supporting assertion on child exceptions for discussion. It would support the following usage:
{ throwsNestedException } | Assert-Throw | Get-ChildException -Recurse | Assert-Any {$_.Message -eq 'the error message I care about'}Notes:
Get-ChildExceptionis similar to that of the ubiquitousGet-ChildItem.Assert-Throwis the[ErrorRecord]thrown not the input[scriptblock]. I'm not sure what the benefit of outputting the input[scriptblock]would be. I didn't find outputting the input[scriptblock]fromAssert-Throwvery useful on its own for chaining because the exception thrown could depend on theAllowNonTerminatingErrorparameter which the downstream functions don't have conclusive access to.I'm mainly interested in whether you think this (or something similar) has a hope of making it into this project. I do have immediate need for assertions for nested exceptions, and I'd like to focus development in the appropriate place: Whether that's contributing to this project or some auxiliary library of my own.