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

returns NaN for free and size, and '' for diskPath when powershell settings have been adjusted on the user's machine #23

Closed
davidburson opened this issue Sep 28, 2022 · 6 comments

Comments

@davidburson
Copy link

My powershell settings cause blank lines to be included parsed in mapOutput, and filter does not remove them, so filtered[0] ends up being an empty string, which causes the invalid return value.

I'll post a PR shortly.

@davidburson
Copy link
Author

davidburson commented Sep 28, 2022

I don't have permission to push a new branch, so here's the diff that shows the fix. I just added driveLetter && to the beginning of the return.

diff --git a/src/index.ts b/src/index.ts
index 27aafee..07a7e42 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -129,7 +129,9 @@ function checkDiskSpace(directoryPath: string, dependencies: Dependencies = {
                        driveData => {
                                // Only get the drive which match the path
                                const driveLetter = driveData[0]
-                               return directoryPath.toUpperCase().startsWith(driveLetter.toUpperCase())
+                               // driveData[0] can be empty string if the user has modified settings related to powershell,
+                               //      causing true to be wrongly returned unless we explicitly check for that case
+                               return driveLetter && directoryPath.toUpperCase().startsWith(driveLetter.toUpperCase())
                        },
                        {
                                diskPath: 0,

@johnheroy
Copy link

@davidburson what powershell settings did you change? curious how to reproduce this

@Nicky03
Copy link

Nicky03 commented Apr 29, 2023

I don't have permission to push a new branch, so here's the diff that shows the fix. I just added driveLetter && to the beginning of the return.

diff --git a/src/index.ts b/src/index.ts
index 27aafee..07a7e42 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -129,7 +129,9 @@ function checkDiskSpace(directoryPath: string, dependencies: Dependencies = {
                        driveData => {
                                // Only get the drive which match the path
                                const driveLetter = driveData[0]
-                               return directoryPath.toUpperCase().startsWith(driveLetter.toUpperCase())
+                               // driveData[0] can be empty string if the user has modified settings related to powershell,
+                               //      causing true to be wrongly returned unless we explicitly check for that case
+                               return driveLetter && directoryPath.toUpperCase().startsWith(driveLetter.toUpperCase())
                        },
                        {
                                diskPath: 0,

@davidburson Now I also encounter the situation of returning 'NAN'. I would like to ask, after adding 'driveLetter &&', can I get the correct value?

@Alex-D Alex-D closed this as completed in e7247ef May 21, 2023
@Alex-D
Copy link
Owner

Alex-D commented May 21, 2023

This will be fixed in the next release :)

I've added a filter to ignore empty lines, should do the work.

@Alex-D
Copy link
Owner

Alex-D commented May 21, 2023

Now fixed in 3.4.0

@davidburson
Copy link
Author

@davidburson what powershell settings did you change? curious how to reproduce this

Sorry for the very slow reply. I can't remember for sure, but here's the changed settings I found, in case it's helpful:

# From https://dev.to/ofhouse/add-a-bash-like-autocomplete-to-your-powershell-4257
# Shows navigable menu of all options when hitting Tab
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

# Autocompletion for arrow keys
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

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

4 participants