Skip to content

Commit d0118a9

Browse files
committed
feature #61308 [Console] Adding more helpful error messages to the Questionhelper (mamazu)
This PR was merged into the 7.4 branch. Discussion ---------- [Console] Adding more helpful error messages to the Questionhelper | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT When trying to debug, having an error like this is not very helpful: ```text 1) Sylius\Bundle\GridBundle\Tests\Functional\Maker\MakeGridTest::it_can_create_grids_interactively Symfony\Component\Console\Exception\MissingInputException: Aborted. symfony/console/Helper/QuestionHelper.php:273 symfony/console/Helper/QuestionHelper.php:139 symfony/console/Helper/QuestionHelper.php:65 symfony/console/Helper/QuestionHelper.php:473 symfony/console/Helper/QuestionHelper.php:67 symfony/console/Style/SymfonyStyle.php:307 symfony/console/Style/SymfonyStyle.php:247 ``` When trying to debug where the error is actually coming from. More helpful would be: ```text 1) Sylius\Bundle\GridBundle\Tests\Functional\Maker\MakeGridTest::it_can_create_grids_interactively Symfony\Component\Console\Exception\MissingInputException: Aborted while asking: Entity class to create a grid for ``` Commits ------- 9aa3023 Adding more helpful error messages to the Questionhelper
2 parents 03d46ea + 9aa3023 commit d0118a9

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
271271
// as opposed to fgets(), fread() returns an empty string when the stream content is empty, not false.
272272
if (false === $c || ('' === $ret && '' === $c && null === $question->getDefault())) {
273273
shell_exec('stty '.$sttyMode);
274-
throw new MissingInputException('Aborted.');
274+
throw new MissingInputException('Aborted while asking: '.$question->getQuestion());
275275
} elseif ("\177" === $c) { // Backspace Character
276276
if (0 === $numMatches && 0 !== $i) {
277277
--$i;

src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ public function testAskThrowsExceptionOnMissingInput()
740740
public function testAskThrowsExceptionOnMissingInputForChoiceQuestion()
741741
{
742742
$this->expectException(MissingInputException::class);
743-
$this->expectExceptionMessage('Aborted.');
743+
$this->expectExceptionMessage('Aborted while asking: Choice');
744744
(new QuestionHelper())->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new ChoiceQuestion('Choice', ['a', 'b']));
745745
}
746746

0 commit comments

Comments
 (0)