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

(GH-110) Handle missing PSDesiredStateConfiguration module for ps group resource #112

Merged
merged 1 commit into from
Aug 2, 2023
Merged

(GH-110) Handle missing PSDesiredStateConfiguration module for ps group resource #112

merged 1 commit into from
Aug 2, 2023

Conversation

michaeltlombardi
Copy link
Collaborator

@michaeltlombardi michaeltlombardi commented Jul 26, 2023

PR Summary

Prior to this change, the PowerShell group resource would fail unexpectedly for operations that didn't include the group, like invoking a different resource.

When the resource's script failed to import the PSDesiredStateConfiguration module, the script errors would bubble up through any DSC invocation. For get, set, and test operations, this is desirable, but not for list, where a missing module means that the group can't provide any resources. Instead of breaking execution for other resources, the script should exit with code 0 for list operations.

PR Context

This change:

  • Adds logic to the beginning of the resource's script, checking for the PSDesiredStateConfiguration module.

  • If the module isn't found, the script raises an error.

  • For the list operation, the script exits with code 0 - being unable to list the DSC Resources is expected on systems that may not have the module installed and aren't trying to list PowerShell DSC Resources explicitly.

    For now, the script has no way to distinguish between being called for a general list operation, like before a dsc resource get command, and a specific list operation, like dsc resource list DSC/PowerShellGroup. It would make sense for the operation to exit with code 1 for the latter.

  • For non-list operations, the script exits with code 1.

@michaeltlombardi michaeltlombardi changed the title (GH-110) Add version logic to PS group resource (GH-110) Handle missing PSDesiredStateConfiguration module for ps group resource Jul 26, 2023
powershellgroup/powershellgroup.resource.ps1 Show resolved Hide resolved
powershellgroup/powershellgroup.resource.ps1 Outdated Show resolved Hide resolved
powershellgroup/powershellgroup.resource.ps1 Outdated Show resolved Hide resolved
powershellgroup/powershellgroup.resource.ps1 Outdated Show resolved Hide resolved
Prior to this change, the PowerShell group resource would fail
unexpectedly for operations that didn't include the group, like
invoking a different resource.

When the resource's script failed to import the
PSDesiredStateConfiguration module, the script errors would bubble up
through any DSC invocation. For `get`, `set`, and `test` operations,
this is desirable, but not for `list`, where a missing module means
that the group can't provide any resources. Instead of breaking
execution for other resources, the script should exit with code `0` for
`list` operations.

This change:

- Adds logic to the beginning of the resource's script, checking for
  the PSDesiredStateConfiguration module.
- If the module isn't found, the script raises an error.
- For the list operation, the script exits with code `0` - being unable
  to list the DSC Resources is expected on systems that may not have
  the module installed and aren't trying to list PowerShell DSC
  Resources explicitly.

  For now, the script has no way to distinguish between being called
  for a general list operation, like before a `dsc resource get`
  command, and a specific list operation, like
  `dsc resource list DSC/PowerShellGroup`. It would make sense for the
  operation to exit with code `1` for the latter.
- For non-list operations, the script exits with code `1`.
@SteveL-MSFT SteveL-MSFT merged commit 5fa5f5b into PowerShell:main Aug 2, 2023
4 checks passed
@SteveL-MSFT SteveL-MSFT deleted the gh-110/main/psgroup-version-handling branch August 2, 2023 00:29
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.

None yet

3 participants