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

Hook handling for package exceptions #11

Open
DailenG opened this issue Oct 10, 2023 · 3 comments
Open

Hook handling for package exceptions #11

DailenG opened this issue Oct 10, 2023 · 3 comments

Comments

@DailenG
Copy link

DailenG commented Oct 10, 2023

I created a hook package that I'm still working on that sends telemetry data to Azure Application Insights. I got it working using custom events but hit a brick wall with error reporting as it seems post-*-all.ps1 doesn't execute if an install fails. My original intent had been to catch the error and send it back to App Insights.

The package usage data is helpful but a large part of the motivation for this came from having a central place to monitor for errors. Would like to see either it execute the post-*.ps1 scripts or perhaps an alternate hook for errors.

@JPRuskin
Copy link

JPRuskin commented Oct 11, 2023

That sounds like a neat application of hooks!

I was surprised it's not working, based on a quick read of the chocolateyScriptRunner.ps1, but it looks like Set-PowerShellExitCode is calling $host.SetShouldExit(), and that's happening just before the post-hooks.

That may be intended, as I can see an argument that hooks are only expected to run after successful installations, but I'll check in with folk.

If there is an issue or enhancement to be made, this issue would be more helpful on the chocolatey/choco repository, (rather than this repository, which is dedicated to hook-packages but not actually how they execute).
We may move it across after discussion, at which point there may be a bunch of additional information required.

@DailenG
Copy link
Author

DailenG commented Oct 11, 2023

Logging and monitoring was actually my original assumption as to the intention of hooks haha

I can see where the expectation is that the post-* scripts only execute when successful. I had the thought of a concept for "error-install-*.ps1" that executes when an error is encountered during package installation. which could be advantageous but perhaps could also be pandora's box :-P i can also see this be particularly helpful for post-failure handling, like cleaning up parts of a failed install or initiating a reboot if one turned out to be necessary, or something more complex like if a reboot is necessary then scheduling a task to run on next start up, setting credentials to allow the next logon to be done without user intervention, then initiating a restart.

I tried using the -ErrorVariable with the chocolatey install commands inside the package scripts but the variable did not seem to populate.

@TheCakeIsNaOH
Copy link
Member

i can also see this be particularly helpful for post-failure handling, like cleaning up parts of a failed install or initiating a reboot if one turned out to be necessary, or something more complex like if a reboot is necessary then scheduling a task to run on next start up, setting credentials to allow the next logon to be done without user intervention, then initiating a restart.

This sounds more like the relm of boxstarter.
https://boxstarter.org/

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

No branches or pull requests

3 participants