Kdyby/Console doesnt catch application error. Why?

mcmatak
Member | 504
+
0
-

When i run CLI

php web/index.php

and somewhere is error, like facebooksdk needs sessions etc., so it ends without any error, not even any error is logged

can somebody explain me why in configuration is these lines?


		$service->catchExceptions = true;
		$service->errorPresenter = 'Nette:Error';
		$service->onError = $this->getService('events.manager')->createEvent(['Nette\Application\Application', 'onError'], $service->onError);
		$self = $this; $service->onError[] = function ($app, $e) use ($self) {
			$app->errorPresenter = false;
			$app->onShutdown[] = function () { exit(254); };
		};

onError[] function cause that the error is not logged, why nette configuration generate this?

how to avoid it?

thanks

David Matějka
Moderator | 6445
+
0
-

Hi, it is better to disable Nette\Application support in kdyby/console using

console:
	application: false

and create separate entrypoint for the console in e.g. /bin/console.php, which may look like this:

<?php declare(strict_types = 1);
if (PHP_SAPI !== 'cli') {
	exit;
}

require __DIR__ . '/../vendor/autoload.php';

$container = App\Bootstrap::boot()->createContainer();
/** @var \Symfony\Component\Console\Application $application */
$application = $container->getService("console.application");
exit($application->run());
mcmatak
Member | 504
+
0
-

thanks,

i stayed at index.php and used this

if (PHP_SAPI === 'cli') {
	$container->getByType(\Kdyby\Console\Application::class)->run();
}

hope it is same, but interesting is that now not started session for facebooksdk is not problem any more, it doesnt throw any exception