cakephp / app

CakePHP application template
370 stars 391 forks source link

Skip using ErrorHandlerMiddleware in cli mode #911

Closed andrii-pukhalevych closed 2 years ago

andrii-pukhalevych commented 2 years ago

This is a (multiple allowed):

Using ErrorHandlerMiddleware in cli mode seems to be not fully correct. It causes using of WebExceptionRenderer in cli mode. In case of specifying ConsoleErrorRenderer in app config it blocks output to stderror.

Shouldn't we skip using ErrorHandlerMiddleware in cli mode?

markstory commented 2 years ago

Shouldn't we skip using ErrorHandlerMiddleware in cli mode?

Probably, but the middleware changing the exception renderer is unexpected to me. Let me try and reproduce this.

markstory commented 2 years ago

Are you running into incorrect output in a command that you're writing, or is it another scenario? Do you have any tips or code on how I could reproduce the issue you're encountering.

andrii-pukhalevych commented 2 years ago

Seems I got this on some old app that didn't use regular way of console commands. Instead, it accepts URL in command line - it was done to run app from both console and browser. In webroot/index.php it has

if (PHP_SAPI === 'cli') {
    $_SERVER['PHP_SELF'] = '/' . basename(__FILE__);
    $_SERVER['REQUEST_URI'] = $argv[1] ?? null;
}

and then

$response = $server->run();
if (PHP_SAPI === 'cli') {
    echo $response->getBody();
} else {
    $server->emit($response);
}