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

Exit with the same exit code as the software being installed #512

Closed
ramiabughazaleh opened this issue Dec 22, 2015 · 39 comments
Closed

Exit with the same exit code as the software being installed #512

ramiabughazaleh opened this issue Dec 22, 2015 · 39 comments

Comments

@ramiabughazaleh
Copy link

ramiabughazaleh commented Dec 22, 2015

I'd like to request allowing choco.exe to return with the same exit code as the package it's installing.

In this way, the calling process can choose how to handle a specific exit code (ex. a reboot).

This request has stemmed from two discussions:
mwrock/Chocolatey-Packages#30
https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/boxstarter/Xf0J6eWYI7s

I'm not sure if this should be the default behavior because it may cause unexpected behavior with boxstarter for example, unless boxstarter is also updated accordingly.

Thank you.

Related to #712, #707, and #709.

@ferventcoder
Copy link
Member

I like it - some questions. Typically choco installs multiple packages at a time, whether through dependencies, packages.config, ir specifying multiple on the command line. When one of those fails, it is easy to say the exit code could be the same for the one that failed.

What should we do when multiple packages fail?

@icnocop
Copy link

icnocop commented Dec 22, 2015

I think the easiest implementation would be for choco to just return the exit code of the last package that failed.

If/when someone wants to know the exit code of previous package failures, we may want to add a command line parameter that instructs choco to stop immediately when any package fails.
I'm not sure if such a parameter already exists.
But in this way, it's a little more flexible.

Thank you.

@ferventcoder
Copy link
Member

It still feels like there is an inconsistency, which can lead to weird expectations. For instance, tell me why you want this feature in the first place?

@ferventcoder
Copy link
Member

@icnocop we do have a stop immediately flag I believe. If not, we may want to add one.

@icnocop
Copy link

icnocop commented Dec 22, 2015

I want this feature so that I could handle the exit codes programmatically myself.

For example, when testing installing a chocolatey package on a VMware virtual machine, there may be a couple of reboots required before the package has successfully been installed.

I expect to programmatically call choco.exe to install one (or more) chocolatey package(s) and wait for it to exit.

If choco.exe returns exit code -2147185721, which means a pending restart is required:
a. Initiate a reboot of the virtual machine
b. Wait for the virtual machine to boot and automatically login back into the desktop
c. Call choco.exe again to continue the installation and wait for it to exit

If choco.exe returns exit code 3010, which means a reboot is required:
a. Initiate a reboot of the virtual machine
b. Wait for the virtual machine to boot and automatically login back into the desktop
c. Call choco.exe again to continue the installation (for any other packages) and wait for it to exit

If choco.exe returns exit code 0, which means that all packages have successfully been installed, then I would take a virtual machine snapshot.

I'm only currently testing choco.exe with one chocolatey package at a time, but I've also included the ability to use this feature with multiple packages in the above scenario.

Thank you.

@ferventcoder
Copy link
Member

@icnocop I'm sure you've heard of boxstarter?

@ferventcoder
Copy link
Member

@icnocop would it be more beneficial for choco to return a special exit code for reboot required? Or do you see other use cases?

The reason I ask is that choco is meant as a unification point - instead of having to track two separate (or more) exit codes, you could track one as choco would know when an install requires a reboot and pass that single exit code to you.

@ferventcoder
Copy link
Member

And for anything it didn't recognize, it could pass back that exit code instead

@icnocop
Copy link

icnocop commented Dec 22, 2015

Yes, I tried to use boxstarter.

See the discussion here: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/boxstarter/Xf0J6eWYI7s

boxstarter.exe doesn't return with an exit code of the package(s) being installed either.

I'm thinking if/maybe when choco has support for this feature, then boxstarter can also be updated to support it, but I believe choco should be first because boxstarter utilizes choco in the first place.

I don't think choco should translate the exit code because different packages may have different exit codes.

@ferventcoder
Copy link
Member

I just meant because boxstarter can handle the reboots for you.

@ferventcoder
Copy link
Member

I don't think choco should translate the exit code because different packages may have different exit codes.

3010 - always always always a reboot exit code for an MSI package.

I'm not sure if you are aware of this or not, but Chocolatey is somewhat smart about the different installers and next year once it is implemented, choco will be able to handle quite a bit more automatically if one just tells Choco what type of installer it is.

@icnocop
Copy link

icnocop commented Dec 22, 2015

Yes, I noticed that Install-ChocolateyPackage already accepts an "installerType" parameter.

I just simply would like to get the exit code of the package after running Install-ChocolateyInstallPackage from either $([System.Environment]::ExitCode or a custom (global?) variable for example.

Thank you.

@ferventcoder
Copy link
Member

@icnocop I understand - I'm simply seeing if there is another avenue we are not thinking about here.

@ferventcoder
Copy link
Member

I know it's hard to see as it's easy to visualize what you already have to deal with and almost impossible to visualize something intangible that may be a better solution. :)

@icnocop
Copy link

icnocop commented Dec 22, 2015

Ok, thank you! 😃

@ferventcoder ferventcoder added this to the 0.9.10 milestone Apr 15, 2016
@ferventcoder ferventcoder self-assigned this Apr 15, 2016
@ferventcoder
Copy link
Member

Let's say we do the simple route for now - per package return

ferventcoder added a commit that referenced this issue Apr 25, 2016
If a package is a warning or an error, display that exit code result
next to the package name.
ferventcoder added a commit that referenced this issue Apr 25, 2016
When running native installers, allow choco to exit with the same exit
code as the installer. Additionally, detect valid exit codes and do not
error when receiving those exit codes.

Pass the exit code to the package so  that result can be passed back.
ferventcoder added a commit that referenced this issue Apr 25, 2016
* stable:
  (maint) rename Get-FileName to Get-WebFileName
  (maint) Log host version as well.
  (GH-512) Exit with same code as installer
  (GH-707) Exit with specific exit codes
  (GH-649) Error if executable is text file
  (GH-709) Get Exit code from PowerShell Host
  (GH-512) Display exit code for packages
  (GH-710) prompt with timeout on some commands
  (maint) better error handling
@jfindlay
Copy link

@ferventcoder, salted chocolate is surprisingly delicious.

@RichiCoder1
Copy link
Contributor

Somehow I missed this issue. I'll work on making sure ChocolateyGUI recognizes and alerts to non-zero and reboot codes.

@ferventcoder
Copy link
Member

@RichiCoder1 sorry man! Totally forgot to mention this to you :/

@ferventcoder
Copy link
Member

It's okay because it's something you will need as you upgrade to 0.9.10

@RichiCoder1
Copy link
Contributor

Nah, you mentioned me here #512 (comment) hence why I noticed this now :)

ferventcoder added a commit that referenced this issue Oct 5, 2016
Starting with 33b6285, which was released as part of GH-512 in
0.9.10, we started checking `$LASTEXITCODE` in addition to the script
command success. This meant it offered the ability to capture when a
script exited with `exit 1` and handle that accordingly. However that
was not a recommended scenario for returning errors from scripts.

Checking `$LastExitCode` checks the last executable's exit code when the
script specifically does not call `Exit`. This can lead to very
perplexing failures, such as running a successful xcopy that exits with
2 and seeing package failures without understanding why. Since it is
not typically recommended to call `Exit` to return a value from
PowerShell because of issues with different hosts, it's less of a
concern to only look at explicit failures.
@basictheprogram
Copy link

Attempting to upgrade the chocolatey package called DraftSight

https://chocolatey.org/packages/draftsight

Ansible win_chocolatey throws a 1603 error

Microsoft says, "Windows Installer is attempting to install an app that is already installed on your PC"

https://support.microsoft.com/en-us/help/834484/you-receive-an-error-1603-a-fatal-error-occurred-during-installation-error-message-when-you-try-to-install-a-windows-installer-package

Upgrading with "cup all" works fine.

Putting this here as it looks like 1603 might be another one of these exit codes?

@ferventcoder
Copy link
Member

@basictheprogram 1603 is a generic error, but rest assured that it is not one of the known good exit codes. Each package can implement their own valid exit codes so if there is a particular exit code an app passes that indicates success that is not one of the defailts, they can passs those in through the package itself.

@basictheprogram
Copy link

basictheprogram commented May 30, 2017

Why doesn't "cup all" or "choco upgrade draftsight" not error? Only when I try to upgrade the package via win_chocolatey does it error.

Looking at the win_chocolatey code it invokes choco so I'm guessing cup and choco.exe are less picky about exit codes?

PS C:\Users\Administrator> choco.exe upgrade draftsight
Chocolatey v0.10.5
Upgrading the following packages:
draftsight
By upgrading you accept licenses for the packages.

You have draftsight v2017.01 installed. Version 2017.02 is available based on your source(s).
Progress: Downloading draftsight 2017.02... 100%

draftsight v2017.02 [Approved]
draftsight package files upgrade completed. Performing other installation steps.
File appears to be downloaded already. Verifying with package checksum to determine if it needs to be redownloaded.
Hashes match.
Hashes match.
Extracting C:\Users\Administrator\AppData\Local\Temp\chocolatey\DraftSight.2017.02\DraftSight64.exe to C:\Users\Administ
rator\AppData\Local\Temp\chocolatey\DraftSight.2017.02...
C:\Users\Administrator\AppData\Local\Temp\chocolatey\DraftSight.2017.02
Installing DraftSight...
DraftSight has been installed.
 The upgrade of draftsight was successful.
  Software installed to 'C:\Program Files\Dassault Systemes\DraftSight\'

Chocolatey upgraded 1/1 packages. 0 packages failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
PS C:\Users\Administrator> $LASTEXITCODE
0

@ferventcoder
Copy link
Member

@basictheprogram looks like win_chocolatey may be coming over WinRm, so you should keep that in mind when using Ansible.

@ferventcoder
Copy link
Member

Not a ton of info in that response sorry. WinRM may behave differently. Ensure you are on the most up to date version of the Chocolatey module and a very recent version of Ansible as well.

@basictheprogram
Copy link

basictheprogram commented May 31, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants