microsoft / Requirements

PowerShell framework for declaratively defining and idempotently imposing system configurations
MIT License
159 stars 26 forks source link

Invoke-requirement fail if set action is not defined #66

Open andrescolodrero opened 4 years ago

andrescolodrero commented 4 years ago

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

jazz127 commented 3 years ago

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?