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

fix(core): Avoid error messages when deleting non-existent environment variable #5547

Merged
merged 7 commits into from
Oct 3, 2023

Conversation

HUMORCE
Copy link
Member

@HUMORCE HUMORCE commented Jun 19, 2023

Description

Motivation and Context

Issue:
When delete environment variable during uninstallation, if the environment variable has been deleted before, we will get a error message.
Examples:

  1. Same environment variable (name) provide by multiple manifests
  2. Delete manually

How Has This Been Tested?

Before:

PS C:\Users\WDAGUtilityAccount> scoop install openssl1 openssl1-light
Installing 'openssl1' (1.1.1u) [64bit] from versions bucket
Loading Win64OpenSSL-1_1_1u.exe from cache
Checking hash of Win64OpenSSL-1_1_1u.exe ... ok.
Extracting Win64OpenSSL-1_1_1u.exe ... done.
Linking ~\scoop\apps\openssl1\current => ~\scoop\apps\openssl1\1.1.1u
Creating shim for 'openssl'.
'openssl1' (1.1.1u) was installed successfully!
Installing 'openssl1-light' (1.1.1u) [64bit] from versions bucket
Loading Win64OpenSSL_Light-1_1_1u.exe from cache
Checking hash of Win64OpenSSL_Light-1_1_1u.exe ... ok.
Extracting Win64OpenSSL_Light-1_1_1u.exe ... done.
Linking ~\scoop\apps\openssl1-light\current => ~\scoop\apps\openssl1-light\1.1.1u
Creating shim for 'openssl'.
WARN  Overwriting shim ('openssl.exe' -> 'openssl.exe') installed from openssl1
'openssl1-light' (1.1.1u) was installed successfully!
PS C:\Users\WDAGUtilityAccount> scoop uninstall openssl1 openssl1-light
Uninstalling 'openssl1' (1.1.1u).
Removing shim 'openssl.shim.openssl1'.
Unlinking ~\scoop\apps\openssl1\current
'openssl1' was uninstalled.
Uninstalling 'openssl1-light' (1.1.1u).
Removing shim 'openssl.shim'.
Removing shim 'openssl.exe'.
Unlinking ~\scoop\apps\openssl1-light\current
Exception calling "DeleteValue" with "1" argument(s): "No value exists with that name."
At C:\Users\WDAGUtilityAccount\scoop\apps\scoop\current\lib\core.ps1:701 char:9
+         $EnvRegisterKey.DeleteValue($name)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentException

'openssl1-light' was uninstalled.

After:

PS C:\Users\WDAGUtilityAccount> scoop install openssl1 openssl1-light
Installing 'openssl1' (1.1.1u) [64bit] from versions bucket
Loading Win64OpenSSL-1_1_1u.exe from cache
Checking hash of Win64OpenSSL-1_1_1u.exe ... ok.
Extracting Win64OpenSSL-1_1_1u.exe ... done.
Linking ~\scoop\apps\openssl1\current => ~\scoop\apps\openssl1\1.1.1u
Creating shim for 'openssl'.
'openssl1' (1.1.1u) was installed successfully!
Installing 'openssl1-light' (1.1.1u) [64bit] from versions bucket
Loading Win64OpenSSL_Light-1_1_1u.exe from cache
Checking hash of Win64OpenSSL_Light-1_1_1u.exe ... ok.
Extracting Win64OpenSSL_Light-1_1_1u.exe ... done.
Linking ~\scoop\apps\openssl1-light\current => ~\scoop\apps\openssl1-light\1.1.1u
Creating shim for 'openssl'.
WARN  Overwriting shim ('openssl.exe' -> 'openssl.exe') installed from openssl1
'openssl1-light' (1.1.1u) was installed successfully!
PS C:\Users\WDAGUtilityAccount> scoop uninstall openssl1 openssl1-light
Uninstalling 'openssl1' (1.1.1u).
Removing shim 'openssl.shim.openssl1'.
Unlinking ~\scoop\apps\openssl1\current
'openssl1' was uninstalled.
Uninstalling 'openssl1-light' (1.1.1u).
Removing shim 'openssl.shim'.
Removing shim 'openssl.exe'.
Unlinking ~\scoop\apps\openssl1-light\current
'openssl1-light' was uninstalled.

Checklist:

  • I have read the Contributing Guide.
  • I have ensured that I am targeting the develop branch.
  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.
  • I have added an entry in the CHANGELOG.

@@ -698,7 +698,7 @@ function env($name, $global, $val = '__get') {
$RegistryValueOption = [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames
$EnvRegisterKey.GetValue($name, $null, $RegistryValueOption)
} elseif ($val -eq $null) {
$EnvRegisterKey.DeleteValue($name)
try { $EnvRegisterKey.DeleteValue($name) } catch { }
Copy link
Member Author

Choose a reason for hiding this comment

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

Operation of adding, deleting environment variable both no output, so a empty catch block here.

@HUMORCE HUMORCE changed the title fix(core): Check if the envrionment variable exists before deletion fix(core): Avoid error messages when deleting non-existent environment variable Jun 19, 2023
niheaven
niheaven previously approved these changes Jun 29, 2023
@rashil2000 rashil2000 merged commit becc7a7 into ScoopInstaller:develop Oct 3, 2023
2 checks passed
CrendKing pushed a commit to CrendKing/Scoop that referenced this pull request Oct 3, 2023
…t variable (ScoopInstaller#5547)

* fix(core): Check if the envrionment variable exists before delete

* CHANGELOG

* Use `try, catch`, value of env variable may is null/empty

* UPDATE CHANGELOG

* Brackets

---------

Co-authored-by: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com>
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.

3 participants