-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[ProgressBar] Empty iterable throws Exception on "maximum number of steps is not set" #47244
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
Comments
|
I am not entirely sure why you want to invert the null-check because the exception is thrown in case Second, are you opting for the As for digging a bit deeper: of course. |
Hey, thanks for your report! |
waiting for review of the PR #47259 |
Hey, thanks for your report! |
Friendly ping? Should this still be open? I will close if I don't hear anything. |
waiting for review of the PR #47259 |
…ray (GromNaN) This PR was merged into the 7.1 branch. Discussion ---------- [Console] Support `ProgressBar::iterate()` on empty array | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #47244 | License | MIT Alternative to #47259 Use `$max = null` to indicate that the value is unknown. This allows `0` to be displayed by directly setting the progress bar to 100%. Zero is only supported for `iterate()`. When passed to the constructor or `setMaxSteps`, it means "unknown max". Commits ------- 574b8a3 Fix ProgressBar::iterate on empty iterator
Symfony version(s) affected
latest
Description
I stumbled upon an empty array that has been used with a progress bar. And my execution stopped. Turns out the ProgressBar checks if its max steps are set when "remaining" and "estimated" values are used in formatting. Nothing wrong so far.
However, in case there is an empty array supplied to the progress bar, code internals interpret a max value of 0 as the max value not being set:
(https://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/Console/Helper/ProgressBar.php#L522 and https://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/Console/Helper/ProgressBar.php#L529)
That to me seems not entirely accurate. Because in this very case, the max value IS set and it IS 0. Yet, it is treated like it is NOT set.
Expected:
I would expect the progress bar not to fail if an empty Iterable is presented to it.
How to reproduce
Possible Solution
Changing the line mentioned above:
(https://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/Console/Helper/ProgressBar.php#L522 and https://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/Console/Helper/ProgressBar.php#L529)
to
seem to be semantically more correct. And it makes the ProgressBar behave like I expected it to do. If you guys are ok with this approach, I can provider a PR.
Additional Context
No response
Thanks!
The text was updated successfully, but these errors were encountered: