codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.4k stars 1.9k forks source link

Bug: showError in CLI/BaseCommand use hardcoded error view path #6656

Closed fpoy closed 2 years ago

fpoy commented 2 years ago

PHP Version

8.1

CodeIgniter4 Version

4.2.7

CodeIgniter4 Installation Method

Composer (as dependency to an existing project)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

cli

Database

MariaDB 10.8

What happened?

I changed the location of the views used to generate errors (from default view files in app/Views/errors/ to app/Views/MyErrors/)

I provided a new path in \Config\Exceptions::$errorViewPath :

public $errorViewPath = APPPATH . 'Views/MyErrors';

When I launch a command that produces an exception :

$ php spark db:create mysql

I obtain the following error :

[ErrorException]
require(/acme/app/Views/errors/cli/error_exception.php): Failed to open stream: No such file or directory
at SYSTEMPATH/CLI/BaseCommand.php:123

Steps to Reproduce

Launch a CLI command that produces an exception (eg create an already existing database) :

$ php spark db:create mysql

Expected Output

I should get a Database Exception :

[CodeIgniter\Database\Exceptions\DatabaseException]
Unable to create the specified database.

Anything else?

No response

kenjis commented 2 years ago

Thank you for reporting. I've confirm the bug: https://github.com/codeigniter4/CodeIgniter4/blob/eff1efe14b521f991e14236dcb5208675fb0e38e/system/CLI/BaseCommand.php#L118-L124

fpoy commented 2 years ago

Thanks, I'll create a PR in a few minutes