Requirements icon indicating copy to clipboard operation
Requirements copied to clipboard

Invoke-requirement fail if set action is not defined

Open andrescolodrero opened this issue 5 years ago • 1 comments

Hi, following your video i found this:

$requirements = @( @{

    Describe = 'Folder tempi present in the system'
    Test     = { test-path -path 'c:/temp' }
    #Set      = { new-item -ItemType Directory -Path 'c:/temp'}
}

)

c:/temp still is not created, but the command fail: pplyRequirement : Failed to apply Requirement 'Folder tempi present in the system' At C:\Program Files\WindowsPowerShell\Modules\Requirements\2.3.6\src\core.ps1:49 char:23

  • $Requirements | % { applyRequirement $_ }
  •                   ~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,applyRequirement

andrescolodrero avatar Jun 23 '20 22:06 andrescolodrero

I hit this issue as well and wanted to add my observations for you/others that may stumble across this post

Basically, this is expected behavior. I think it would be great if the Readme was clearer in explaining this because we've obviously both missed it.

#54 was my guidance in suggesting that further tests should not be processed so the "apply error" is returned when exiting Invoke-Requirement once the test fails (and can't be remediated due to the lack of Set)

Side note that Test-Requirement does seem to process all Tests regardless of errors but wouldn't help if you want to use Set.

I'm not sure if this should be a separate feature request/post but when using Invoke-Requirement, it might be nice to have the option to suppress errors like this and return a "skipped" state or similar for tests that were not processed after an error occurs.

I think this might help with problems I'm having with format-checklist as well. When a failed requirement occurs the line below returns $null and then I get "Format-Checklist : Cannot index into a null array." when $nextFsm is subsequently used. Interestingly, this occurs even when using Test-Requirement.

$nextFsm = &$nextFsm[$stateVector] @transitionArgs

Not wanting to push my luck but while we are here, maybe even a switch to process all requirements regardless could be provided as well?

jazz127 avatar Jan 31 '21 01:01 jazz127