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

Skip to content

Commit 6c1cd01

Browse files
committed
Dispatch console error event
1 parent 62789d6 commit 6c1cd01

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,25 +217,32 @@ public function doRun(InputInterface $input, OutputInterface $output)
217217
// the command name MUST be the first element of the input
218218
$command = $this->find($name);
219219
} catch (\Throwable $e) {
220-
if (null !== $this->dispatcher) {
221-
$event = new ConsoleErrorEvent($input, $output, $e);
222-
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
220+
if (!($e instanceof CommandNotFoundException && !$e instanceof NamespaceNotFoundException) || 1 !== count($alternatives = $e->getAlternatives()) || !$input->isInteractive()) {
221+
if (null !== $this->dispatcher) {
222+
$event = new ConsoleErrorEvent($input, $output, $e);
223+
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
223224

224-
if (0 === $event->getExitCode()) {
225-
return 0;
226-
}
225+
if (0 === $event->getExitCode()) {
226+
return 0;
227+
}
227228

228-
$e = $event->getError();
229-
}
229+
$e = $event->getError();
230+
}
230231

231-
if (!($e instanceof CommandNotFoundException && !$e instanceof NamespaceNotFoundException) || 1 !== count($alternatives = $e->getAlternatives()) || !$input->isInteractive()) {
232232
throw $e;
233233
}
234234

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

238238
if (!(new QuestionHelper())->ask($input, $output, $question)) {
239+
if (null !== $this->dispatcher) {
240+
$event = new ConsoleErrorEvent($input, $output, $e);
241+
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
242+
243+
return $event->getExitCode();
244+
}
245+
239246
return 1;
240247
}
241248

0 commit comments

Comments
 (0)
0