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

(#967) Parse Info messages for errors #1042

Merged
merged 2 commits into from
Apr 5, 2024

Conversation

corbob
Copy link
Member

@corbob corbob commented Apr 3, 2024

Description Of Changes

This updates the handling of messages from Chocolatey.Lib to parse for ERROR, WARN, and FATAL messages and include them in the error message.

Motivation and Context

When run through self service, Chocolatey Agent calls Chocolatey CLI and reports back the results. Due to this, all messages are output on Standard Output.

Testing

In order to test this, you need to check out the PRs mentioned at the bottom. This is due to some minor debug specific changes to the projects other projects. To try and make setup and debugging easier, I've added some files to a gist: https://gist.github.com/corbob/e1d021ccec9586a9e85061ee077b55dd

For the purposes of testing this, all repositories were checked out into C:\git. You can check them out wherever you normally have them checked out, just adjust samples accordingly. I have also added a source location called local that is mapped to C:\packages and contains the throws-message package from the gist. Feel free to adjust the Chocolatey configuration file for your own system.

The Chocolatey Configuration file was generated by running the below in the src\chocolatey\bin\debug directory of the Chocolatey Licensed Extension after building the project.

# Self-Service configuration
.\choco feature disable --name="'showNonElevatedWarnings'" --allow-unofficial -y
.\choco feature enable --name="'useBackgroundService'" --allow-unofficial -y
.\choco feature enable --name="'useBackgroundServiceWithNonAdministratorsOnly'" --allow-unofficial -y
.\choco feature enable --name="'allowBackgroundServiceUninstallsFromUserInstallsOnly'" --allow-unofficial -y
.\choco config set --name="'backgroundServiceAllowedCommands'" --value="'install,upgrade,uninstall'" --allow-unofficial -y
.\choco source add -n local -s C:\packages\ --allow-self-service --allow-unofficial -y

Initial Preparations:

  1. Start a PowerShell prompt and navigate to C:\git
  2. Run git clone https://gist.github.com/corbob/e1d021ccec9586a9e85061ee077b55dd.git
  3. Run choco pack .\e1d021ccec9586a9e85061ee077b55dd\throw-message.nuspec --out C:\packages
  4. Run copy .\e1d021ccec9586a9e85061ee077b55dd\chocolatey.config .
  5. Create a local non-administrator user.

Testing the changes:

  1. Launch PowerShell as the non-administrator user.
  2. Set $env:CHOCO_SOURCE_LOCATION and $env:CHOCO_PRO_SOURCE_LOCATION to point to C:\git\choco and C:\git\choco-licensed\ respectively. (These will not be set by default on the Developer VM as this is a different user account.)
  3. Navigate to C:\git\chocolateygui-licensed
  4. Run the .\Get-ChocolateyGuiUpdatedDebugVersion.ps1 script.
  5. Run & 'C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\devenv.exe' to start Visual Studio as this non-administrative user.
  6. Open the Chocolatey GUI Licensed Extension solution.
  7. Set it up for debugging.
  8. Launch PowerShell as administrator.
  9. Run $env:DebugChocolateyInstall = 'C:\git\choco-licensed\src\chocolatey\bin\debug'
  10. Run & 'C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\devenv.exe' to start Visual Studio as administrator with this environment variable set.
  11. Open the Chocolatey Agent solution.
  12. Start debugging both Chocolatey Agent and Chocolatey GUI Licensed Extension.
  13. Attempt to install throw-message from the local source in the Chocolatey GUI window.
  14. Verify that it fails, and outputs the error message expected:

image

Operating Systems Testing

Windows 10

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v2 compatibility checked?

Related Issue

corbob added 2 commits April 3, 2024 09:03
Chocolatey Agent runs Chocolatey CLI and reports the results back to
Chocolatey GUI. As a result, all of the messages come back as "Info"
messages. This adds handling to the GrabErrors method to check Info
messages for clues that they're actually `Error`, `Warning`, or `Fatal`
messages.
@corbob corbob force-pushed the Debugging-Changes branch from 2c8726e to 28155f8 Compare April 3, 2024 16:06
Copy link
Member

@gep13 gep13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@gep13
Copy link
Member

gep13 commented Apr 5, 2024

@corbob thank you for the detailed instructions on how to take this for a spin.

Happy to say that this is working as expected!

@gep13 gep13 merged commit 86e6f63 into chocolatey:hotfix/2.1.1 Apr 5, 2024
2 checks passed
@corbob corbob deleted the Debugging-Changes branch April 5, 2024 13: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.

Chocolatey GUI not displaying error output when running as non-admin through Background Service
2 participants