upgrade command returns an exit code of '0' (zero), when the repository can't be reached
- Dominant language
- C#
- Stars
- 11.5k
- Forks
- 960
- PR merge metrics
- No merged PRs in 30d
Description
### Checklist
- [X] I have verified this is the correct repository for opening this issue.
- [X] I have verified no other issues exist related to my problem.
- [X] I have verified this is not an issue for a specific package.
- [X] I have verified this issue is not security related.
### What You Are Seeing?
I'm creating a scheduled task on Windows, which calls this command:
`%ProgramData%\chocolatey\bin\choco.exe upgrade all --yes --log-file="%ProgramData%\chocolatey\logs\upgrade.log"`
It will be automatically started, whenever a user logons on Windows. I also added a condition that if the task failed, then it will be restarted 2 hours later.
Now to the problem: if the user logons into windows and he hasn't internet, Chocolatey will see this:
```
2022-12-15 17:50:39,095 33608 [WARN ] - Error retrieving packages from source 'https://community.chocolatey.org/api/v2/':
Der Remotename konnte nicht aufgelöst werden: 'community.chocolatey.org'
```
Which means that the repository web address couldn't be reached and it is threaten as a warning. At the end it returns an exit code of '0' (Success), which is wrong:
`2022-12-15 17:50:39,117 33608 [DEBUG] - Exiting with 0`
So, by looking the task protocol, I will see:
`Task Scheduler successfully finished "{bc42c0cf-bd87-41a8-8bce-8f29c186b0bf}" instance of the "\Update Chocolatey packages" task for user "NT-AUTORITÄT\SYSTEM".`
So, the task won't be started again because for Windows it was finished correctly.
### What is Expected?
**chocolatey upgrade** should return an error code different than '0' (zero) if the repository couldn't be reached.
### How Did You Get This To Happen?
The command:
`%ProgramData%\chocolatey\bin\choco.exe upgrade all --yes --log-file="%ProgramData%\chocolatey\logs\upgrade.log"`
will be ran by a scheduled Windows task.
### System Details
* Operating System: Windows 10 / 20H2
* Windows PowerShell version: 5.1.19041.1682
* Chocolatey CLI Version: 1.2.1
* Chocolatey Licensed Extension version: Chocolatey v1.2.1
* Chocolatey License type: open source
* Terminal/Emulator: It will be ran from the task scheduler directly
### Installed Packages
```bash
anydesk 6.1.5.0
anydesk.portable 7.1.6
chocolatey 1.2.1
chocolatey-compatibility.extension 1.0.0
chocolatey-core.extension 1.4.0
```
### Output Log
```bash
2022-12-15 17:50:38,611 33608 [INFO ] - Chocolatey v1.2.1
2022-12-15 17:50:38,617 33608 [DEBUG] - Chocolatey is running on Windows v 10.0.19042.0
2022-12-15 17:50:38,620 33608 [DEBUG] - Attempting to delete file "C:/ProgramData/chocolatey/choco.exe.old".
2022-12-15 17:50:38,621 33608 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\choco.exe.old".
2022-12-15 17:50:38,632 33608 [DEBUG] - Command line: "C:\ProgramData\chocolatey\choco.exe" upgrade all --yes --log-file="C:\ProgramData\chocolatey\logs\upgrade.log"
2022-12-15 17:50:38,633 33608 [DEBUG] - Received arguments: upgrade all --yes --log-file=C:\ProgramData\chocolatey\logs\upgrade.log
2022-12-15 17:50:38,677 33608 [DEBUG] - RemovePendingPackagesTask is now ready and waiting for PreRunMessage.
2022-12-15 17:50:38,685 33608 [DEBUG] - Sending message 'PreRunMessage' out if there are subscribers...
2022-12-15 17:50:38,693 33608 [DEBUG] - [Pending] Removing all pending packages that should not be considered installed...
2022-12-15 17:50:38,727 33608 [DEBUG] - Performing validation checks.
2022-12-15 17:50:38,731 33608 [DEBUG] - Global Configuration Validation Checks:
2022-12-15 17:50:38,733 33608 [DEBUG] - - Package Exit Code / Exit On Reboot = Checked
2022-12-15 17:50:38,736 33608 [DEBUG] - System State Validation Checks:
2022-12-15 17:50:38,738 33608 [DEBUG] - Reboot Requirement Checks:
2022-12-15 17:50:38,740 33608 [DEBUG] - - Pending Computer Rename = Checked
2022-12-15 17:50:38,741 33608 [DEBUG] - - Pending Component Based Servicing = Checked
2022-12-15 17:50:38,743 33608 [DEBUG] - - Pending Windows Auto Update = Checked
2022-12-15 17:50:38,744 33608 [DEBUG] - - Pending File Rename Operations = Ignored
2022-12-15 17:50:38,745 33608 [DEBUG] - - Pending Windows Package Installer = Checked
2022-12-15 17:50:38,746 33608 [DEBUG] - - Pending Windows Package Installer SysWow64 = Checked
2022-12-15 17:50:38,750 33608 [INFO ] - 2 validations performed. 2 success(es), 0 warning(s), and 0 error(s).
2022-12-15 17:50:38,767 33608 [DEBUG] - The source 'https://community.chocolatey.org/api/v2/' evaluated to a 'normal' source type
2022-12-15 17:50:38,769 33608 [DEBUG] -
NOTE: Hiding sensitive configuration data! Please double and triple
check to be sure no sensitive data is shown, especially if copying
output to a gist for review.
2022-12-15 17:50:38,777 33608 [DEBUG] - Configuration: CommandName='upgrade'|CacheLocation='C:\WINDOWS\TEMP\chocolatey'|
ContainsLegacyPackageInstalls='True'|
CommandExecutionTimeoutSeconds='2700'|WebRequestTimeoutSeconds='30'|
Sources='https://community.chocolatey.org/api/v2/'|SourceType='normal'|
Debug='False'|Verbose='False'|Trace='False'|Force='False'|Noop='False'|
HelpRequested='False'|UnsuccessfulParsing='False'|RegularOutput='True'|
QuietOutput='False'|PromptForConfirmation='False'|
DisableCompatibilityChecks='False'|AcceptLicense='True'|
AllowUnofficialBuild='False'|
AdditionalLogFileLocation='C:\ProgramData\chocolatey\logs\upgrade.log'|
Input='all'|AllVersions='False'|SkipPackageInstallProvider='False'|
SkipHookScripts='False'|PackageNames='all'|Prerelease='False'|
ForceX86='False'|OverrideArguments='False'|NotSilent='False'|
ApplyPackageParametersToDependencies='False'|
ApplyInstallArgumentsToDependencies='False'|IgnoreDependencies='False'|
AllowMultipleVersions='False'|AllowDowngrade='False'|
ForceDependencies='False'|PinPackage='False'|
Information.PlatformType='Windows'|
Information.PlatformVersion='10.0.19042.0'|
Information.PlatformName='Windows 10'|
Information.ChocolateyVersion='1.2.1.0'|
Information.ChocolateyProductVersion='1.2.1'|
Information.FullName='choco, Version=1.2.1.0, Culture=neutral, PublicKeyToken=79d02ea9cad655eb'|
Information.Is64BitOperatingSystem='True'|
Information.Is64BitProcess='True'|Information.IsInteractive='False'|
Information.UserName='SYSTEM'|Information.UserDomainName='D'|
Information.IsUserAdministrator='True'|
Information.IsUserSystemAccount='True'|
Information.IsUserRemoteDesktop='False'|
Information.IsUserRemote='True'|
Information.IsProcessElevated='True'|
Information.IsLicensedVersion='False'|Information.LicenseType='Foss'|
Information.CurrentDirectory='C:\WINDOWS\system32'|
Features.AutoUninstaller='True'|Features.ChecksumFiles='True'|
Features.AllowEmptyChecksums='False'|
Features.AllowEmptyChecksumsSecure='True'|
Features.FailOnAutoUninstaller='False'|
Features.FailOnStandardError='False'|Features.UsePowerShellHost='True'|
Features.LogEnvironmentValues='False'|Features.LogWithoutColor='False'|
Features.VirusCheck='False'|
Features.FailOnInvalidOrMissingLicense='False'|
Features.IgnoreInvalidOptionsSwitches='True'|
Features.UsePackageExitCodes='True'|
Features.UseEnhancedExitCodes='False'|
Features.UseFipsCompliantChecksums='False'|
Features.ShowNonElevatedWarnings='True'|
Features.ShowDownloadProgress='True'|
Features.StopOnFirstPackageFailure='False'|
Features.UseRememberedArgumentsForUpgrades='False'|
Features.IgnoreUnfoundPackagesOnUpgradeOutdated='False'|
Features.SkipPackageUpgradesWhenNotInstalled='False'|
Features.RemovePackageInformationOnUninstall='False'|
Features.ExitOnRebootDetected='False'|
Features.LogValidationResultsOnWarnings='True'|
Features.UsePackageRepositoryOptimizations='True'|
ListCommand.LocalOnly='False'|ListCommand.IdOnly='False'|
ListCommand.IncludeRegistryPrograms='False'|ListCommand.PageSize='25'|
ListCommand.Exact='False'|ListCommand.ByIdOnly='False'|
ListCommand.ByTagOnly='False'|ListCommand.IdStartsWith='False'|
ListCommand.OrderByPopularity='False'|ListCommand.ApprovedOnly='False'|
ListCommand.DownloadCacheAvailable='False'|
ListCommand.NotBroken='False'|
ListCommand.IncludeVersionOverrides='False'|
UpgradeCommand.FailOnUnfound='False'|
UpgradeCommand.FailOnNotInstalled='False'|
UpgradeCommand.NotifyOnlyAvailableUpgrades='False'|
UpgradeCommand.ExcludePrerelease='False'|
NewCommand.AutomaticPackage='False'|
NewCommand.UseOriginalTemplate='False'|SourceCommand.Command='unknown'|
SourceCommand.Priority='0'|SourceCommand.BypassProxy='False'|
SourceCommand.AllowSelfService='False'|
SourceCommand.VisibleToAdminsOnly='False'|
FeatureCommand.Command='unknown'|ConfigCommand.Command='unknown'|
ApiKeyCommand.Remove='False'|PinCommand.Command='unknown'|
OutdatedCommand.IgnorePinned='False'|
ExportCommand.IncludeVersionNumbers='False'|Proxy.BypassOnLocal='True'|
TemplateCommand.Command='unknown'|
2022-12-15 17:50:38,779 33608 [DEBUG] - _ Chocolatey:ChocolateyUpgradeCommand - Normal Run Mode _
2022-12-15 17:50:38,783 33608 [INFO ] - Upgrading the following packages:
2022-12-15 17:50:38,785 33608 [INFO ] - all
2022-12-15 17:50:38,786 33608 [INFO ] - By upgrading, you accept licenses for the packages.
2022-12-15 17:50:38,839 33608 [DEBUG] - Running list with the following filter = ''
2022-12-15 17:50:38,840 33608 [DEBUG] - --- Start of List ---
2022-12-15 17:50:38,946 33608 [WARN ] -
anydesk has been installed as a side by side installation.
Side by side installations are deprecated and is pending removal in v2.0.0.
2022-12-15 17:50:38,948 33608 [DEBUG] - anydesk 6.1.5.0
2022-12-15 17:50:38,952 33608 [WARN ] -
anydesk.portable has been installed as a side by side installation.
Side by side installations are deprecated and is pending removal in v2.0.0.
2022-12-15 17:50:38,954 33608 [DEBUG] - anydesk.portable 7.1.6
2022-12-15 17:50:38,955 33608 [DEBUG] - chocolatey 1.2.1
2022-12-15 17:50:38,956 33608 [DEBUG] - chocolatey-compatibility.extension 1.0.0
2022-12-15 17:50:38,958 33608 [DEBUG] - chocolatey-core.extension 1.4.0
2022-12-15 17:50:38,960 33608 [DEBUG] - --- End of List ---
2022-12-15 17:50:38,989 33608 [DEBUG] - Using 'https://community.chocolatey.org/api/v2/'.
2022-12-15 17:50:39,060 33608 [WARN ] - Error retrieving packages from source 'https://community.chocolatey.org/api/v2/':
Der Remotename konnte nicht aufgelöst werden: 'community.chocolatey.org'
2022-12-15 17:50:39,061 33608 [WARN ] -
anydesk was not found with the source(s) listed.
If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.
Version: ""; Source(s): "https://community.chocolatey.org/api/v2/"
2022-12-15 17:50:39,066 33608 [DEBUG] - Using 'https://community.chocolatey.org/api/v2/'.
2022-12-15 17:50:39,068 33608 [WARN ] - Error retrieving packages from source 'https://community.chocolatey.org/api/v2/':
Der Remotename konnte nicht aufgelöst werden: 'community.chocolatey.org'
2022-12-15 17:50:39,069 33608 [WARN ] -
anydesk.portable was not found with the source(s) listed.
If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.
Version: ""; Source(s): "https://community.chocolatey.org/api/v2/"
2022-12-15 17:50:39,078 33608 [DEBUG] - Using 'https://community.chocolatey.org/api/v2/'.
2022-12-15 17:50:39,080 33608 [WARN ] - Error retrieving packages from source 'https://community.chocolatey.org/api/v2/':
Der Remotename konnte nicht aufgelöst werden: 'community.chocolatey.org'
2022-12-15 17:50:39,081 33608 [WARN ] -
chocolatey was not found with the source(s) listed.
If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.
Version: ""; Source(s): "https://community.chocolatey.org/api/v2/"
2022-12-15 17:50:39,087 33608 [DEBUG] - Using 'https://community.chocolatey.org/api/v2/'.
2022-12-15 17:50:39,089 33608 [WARN ] - Error retrieving packages from source 'https://community.chocolatey.org/api/v2/':
Der Remotename konnte nicht aufgelöst werden: 'community.chocolatey.org'
2022-12-15 17:50:39,090 33608 [WARN ] -
chocolatey-compatibility.extension was not found with the source(s) listed.
If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.
Version: ""; Source(s): "https://community.chocolatey.org/api/v2/"
2022-12-15 17:50:39,094 33608 [DEBUG] - Using 'https://community.chocolatey.org/api/v2/'.
2022-12-15 17:50:39,095 33608 [WARN ] - Error retrieving packages from source 'https://community.chocolatey.org/api/v2/':
Der Remotename konnte nicht aufgelöst werden: 'community.chocolatey.org'
2022-12-15 17:50:39,097 33608 [WARN ] -
chocolatey-core.extension was not found with the source(s) listed.
If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.
Version: ""; Source(s): "https://community.chocolatey.org/api/v2/"
2022-12-15 17:50:39,105 33608 [WARN ] -
Chocolatey upgraded 0/5 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
2022-12-15 17:50:39,106 33608 [INFO ] -
2022-12-15 17:50:39,108 33608 [WARN ] - Warnings:
2022-12-15 17:50:39,109 33608 [WARN ] - - anydesk - anydesk was not found with the source(s) listed.
2022-12-15 17:50:39,110 33608 [WARN ] - - chocolatey-core.extension - chocolatey-core.extension was not found with the source(s) listed.
2022-12-15 17:50:39,111 33608 [WARN ] - - chocolatey - chocolatey was not found with the source(s) listed.
2022-12-15 17:50:39,112 33608 [WARN ] - - anydesk.portable - anydesk.portable was not found with the source(s) listed.
2022-12-15 17:50:39,113 33608 [WARN ] - - chocolatey-compatibility.extension - chocolatey-compatibility.extension was not found with the source(s) listed.
2022-12-15 17:50:39,115 33608 [DEBUG] - Sending message 'PostRunMessage' out if there are subscribers...
2022-12-15 17:50:39,117 33608 [DEBUG] - Exiting with 0
```
### Additional Context
**Windows Scheduler log**
```
Log Name: Microsoft-Windows-TaskScheduler/Operational
Source: Microsoft-Windows-TaskScheduler
Date: 15.12.2022 17:50:39
Event ID: 102
Task Category: Task completed
Level: Information
Keywords: (1)
User: SYSTEM
Computer: mylaptop
Description:
Task Scheduler successfully finished "{bc42c0cf-bd87-41a8-8bce-8f29c186b0bf}" instance of the "\Update Chocolatey packages" task for user "NT-AUTORITÄT\SYSTEM".
Event Xml:
102
0
4
102
2
0x8000000000000001
1257658
Microsoft-Windows-TaskScheduler/Operational
mylaptop
\Update Chocolatey packages
NT-AUTORITÄT\SYSTEM
{bc42c0cf-bd87-41a8-8bce-8f29c186b0bf}
```
_No response_
Contributor guide
Research direction
No source files or tests are named. Reproduce the upgrade command with an unreachable repository, then trace how repository retrieval warnings are converted into the command's exit code. Done means the failure returns a nonzero code and has regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100