8000 [Console] ProgressBar::getMessage throws TypeError when message not defined · Issue #54386 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Console] ProgressBar::getMessage throws TypeError when message not defined #54386
Closed
@kadet1090

Description

@kadet1090

Symfony version(s) affected

6.3.0-beta+

Description

When trying to obtain message from ProgressBar that was not set previously using setMessage, the getMessage method throws TypeError.

In ProgressBar.php line 188:
                                                                                                                  
  [TypeError]                                                                                                     
  Symfony\Component\Console\Helper\ProgressBar::getMessage(): Return value must be of type string, null 
  

The workaround is to catch the TypeError but it is not elegant solution.

How to reproduce

$progressBar = new ProgressBar($output);
$progressBar->getMessage(); // throws TypeError

Possible Solution

  • Change type hint of ProgressBar->getMessage() to ?string instead of string, add $default argument + ?? $default to the code.
  • Add method like hasMessage(string $name = 'message') to check if message is available

Additional Context

I have custom service that updates the progress bar only if necessary and thus I have to check if message that was supplied differs from the one that is already set:
https://github.com/cojedzie/cojedzie/blob/master/api/src/DataImport/ConsoleProgressReporter.php#L52-L55

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0