8000 Dispatch console error event · symfony/symfony@9fb4365 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9fb4365

Browse files
committed
Dispatch console error event
1 parent f42a2bb commit 9fb4365

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines cha 10000 nged

src/Symfony/Component/Console/Application.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,25 +225,32 @@ public function doRun(InputInterface $input, OutputInterface $output)
225225
// the command name MUST be the first element of the input
226226
$command = $this->find($name);
227227
} catch (\Throwable $e) {
228-
if (null !== $this->dispatcher) {
229-
$event = new ConsoleErrorEvent($input, $output, $e);
230-
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
228+
if (!($e instanceof CommandNotFoundException && !$e instanceof NamespaceNotFoundException) || 1 !== count($alternatives = $e->getAlternatives()) || !$input->isInteractive()) {
229+
if (null !== $this->dispatcher) {
230+
$event = new ConsoleErrorEvent($input, $output, $e);
231+
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
231232

232-
if (0 === $event->getExitCode()) {
233-
return 0;
234-
}
233+
if (0 === $event->getExitCode()) {
234+
return 0;
235+
}
235236

236-
$e = $event->getError();
237-
}
237+
$e = $event->getError();
238+
}
238239

239-
if (!($e instanceof CommandNotFoundException && !$e instanceof NamespaceNotFoundException) || 1 !== count($alternatives = $e->getAlternatives()) || !$input->isInteractive()) {
240240
throw $e;
241241
}
242242

243243
$alternative = $alternatives[0];
244244
$question = new ConfirmationQuestion(sprintf("<error>Command \"%s\" is not defined.</error>\n\nDo you want to run \"%s\" instead? [y/n] ", $name, $alternative), false);
245245

246246
if (!(new QuestionHelper())->ask($input, $output, $question)) {
247+
if (null !== $this->dispatcher) {
248+
$event = new ConsoleErrorEvent($input, $output, $e);
249+
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
250+
251+
return $event->getExitCode();
252+
}
253+
247254
return 1;
248255
}
249256

0 commit comments

Comments
 (0)
0