-
Notifications
You must be signed in to change notification settings - Fork 905
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
Checking for presence of Chocolatey license file in tab expansion PowerShell script generates $error
#3218
Comments
Well this is an interesting one... I am seeing this on a VM, but it looks like there should be Pester tests testing this (at least within PowerShell 2... As well as this code: choco/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 Lines 113 to 119 in 06acb28
Which should be removing the error (and when I manually run those, the error is removed). |
The method we were using to clear the error variable wasn't clearing the variable. Instead of trying this way, it's better to use Test-Path to verify if a file exists.
The method we were using to clear the error variable wasn't clearing the variable. Instead of trying this way, it's better to use Test-Path to verify if a file exists.
(#3218) Update Tab Expansion to use Test-Path
Well i don't know why the |
@aetonsi the fix is assigned to the 2.1.0 milestone, so it should come out with that release when it is ready. At this point I can't say for sure when that might be, but I do expect it to be the next release. In the meantime, a workaround you could consider is moving the test for errors to before the Chocolatey profile loading, and thus circumvent this issue. |
Thank you again, have a nice day. |
$error
s in helper file(s)$error
s in helper file(s) in tab expansion PowerShell script
$error
s in helper file(s) in tab expansion PowerShell script$error
* release/2.1.0: (52 commits) (maint) If statement formatting change (#3224) Add Assembly Loaded configuration option (maint) Resave without BOM (#3224) Update version check tests (#3174) Store non-normalized package version (maint) Add required whitespace (#3225) Add Pester Tests to ensure environment (#3201 #3225) Re-instate setting of config values (maint) Remove env variable for release version (maint) Fix encoding of file (#3194) Add tab completion for cache command (#2854) Re-save file with UTF-8 with BOM (#3218) Update Tab Expansion to use Test-Path (#3218) Remove try catch block for tab completion (build) Use latest Chocolatey.Cake.Recipe package (#2854) Do Write-Error instead of Write-Warning (#2854) Pester tests to Get-ChocolateyConfigValue (maint) Resave Get-ChocolateyConfigValue as CRLF (#2854) Add helper to read config values (#3214) Add Pester tests to ensure cache cleared ...
🎉 This issue has been resolved in version 2.1.0 🎉 The release is available on: Your GitReleaseManager bot 📦🚀 |
* master: (maint) If statement formatting change (#3224) Add Assembly Loaded configuration option (maint) Resave without BOM (#3224) Update version check tests (#3174) Store non-normalized package version (maint) Add required whitespace (#3225) Add Pester Tests to ensure environment (#3201 #3225) Re-instate setting of config values (maint) Remove env variable for release version (maint) Fix encoding of file (#3194) Add tab completion for cache command (#2854) Re-save file with UTF-8 with BOM (#3218) Update Tab Expansion to use Test-Path (#3218) Remove try catch block for tab completion
Checklist
Is Your Feature Request Related To A Problem? Please describe.
Hi, i'd like to suggest a simple micro improvement.
The following lines in the "Tab Expansion" helper check for the presence of a license file:
choco/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1
Lines 64 to 70 in 06acb28
But it does so by relying on a
try{}catch
edGet-Item -ErrorAction Stop
. This doesn't print any error, but it still populates the automatic variable$Error
with an unneeded exception.I am importing
chocolateyProfile.psm1
which in turn imports this file, in my powershell's$PROFILE
file.At the end of my profile file i do a simple error checking on
$Error
. Ever since chocolatey v2 came out, i always have this false positive:This also causes the
$Error
variable to always start off with 1 item in every single PS session.Describe The Solution. Why is it needed?
A very simple solution would be to use
Test-Path
instead ofGet-Item
, and then useget-item
to fetch the file if needed.Additional Context
Related Issues
(maybe) #2851
The text was updated successfully, but these errors were encountered: