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

Write-Progress incorrectly shows 100% until 1% of the task is completed #18850

Closed
5 tasks done
wi-fr opened this issue Dec 26, 2022 · 3 comments · Fixed by #18735
Closed
5 tasks done

Write-Progress incorrectly shows 100% until 1% of the task is completed #18850

wi-fr opened this issue Dec 26, 2022 · 3 comments · Fixed by #18735
Labels
Resolution-Fixed The issue is fixed.

Comments

@wi-fr
Copy link

wi-fr commented Dec 26, 2022

Prerequisites

Steps to reproduce

for ($i = 0; $i -le 2; $i += 0.1) { 
  Write-Progress -Activity 'DEMO' -Status $i -PercentComplete ([int]$i)
  Start-Sleep 1
}


### Expected behavior

```console
The progress bar shows 0% before 1% of the task is completed.

Actual behavior

The progress bar shows 100% before 1% of the task is completed.

In Windows PowerShell 5.1 the code snippet works as expected.

Error details

No error

Environment data

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.1
PSEdition                      Core
GitCommitId                    7.3.1
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}       
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

@wi-fr wi-fr added the Needs-Triage The issue is new and needs to be triaged by a work group. label Dec 26, 2022
@mklement0
Copy link
Contributor

mklement0 commented Dec 26, 2022

Good find; let me boil it down to the core problem:

  • -Percent 0 is incorrectly treated like -Percent 100, i.e. the whole progress bar is unexpectedly filled in; with $PSStyle.Progress.View = 'Classic', nothing is shown.
# !! Shows the whole bar filled in, as if -PercentComplete 100 had been passed.
# !! If $PSStyle.Progress.View = 'Classic', nothing shows at all.
Write-Progress -Activity Test -Status '0% complete' -PercentComplete 0; Start-Sleep 3

# OK: any value greater than 0 (1 - 100) - only the proportion reflecting the percentage is filled in.
Write-Progress -Activity Test -Status '1% complete' -PercentComplete 1; Start-Sleep 3

@SteveL-MSFT
Copy link
Member

SteveL-MSFT commented Dec 28, 2022

I found and fixed this as part of this PR: https://github.com/PowerShell/PowerShell/pull/18735/files#diff-cbda13b2a2d772c7dc93249087ce0e6b94bfdc7d022ab9eea9a752610674ab71R427

GitHub
PR Summary To show useful progress, this change requires collecting total files/bytes information first. The initial collection of total files and bytes is on a separate thread so no impact to sta...

@ghost ghost added the In-PR Indicates that a PR is out for the issue label Dec 28, 2022
@SteveL-MSFT SteveL-MSFT removed the Needs-Triage The issue is new and needs to be triaged by a work group. label Dec 28, 2022
@ghost ghost added Resolution-Fixed The issue is fixed. and removed In-PR Indicates that a PR is out for the issue labels Jan 25, 2023
@ghost
Copy link

ghost commented Mar 14, 2023

🎉This issue was addressed in #18735, which has now been successfully released as v7.4.0-preview.2.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Fixed The issue is fixed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants