codeigniter4 / CodeIgniter4

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

"CodeIgniter\Debug\ExceptionHandler::handle" show error condition add "CI_DEBUG" suggest #9120

Closed juangws closed 2 months ago

juangws commented 3 months ago

in a custom environment. And the environment name is not "development" or "testing". has Internal Server Error in "ajax", not working. It is recommended to change the "system/Debug/ExceptionHandler.php" code: == source code ===

$data = (ENVIRONMENT === 'development' || ENVIRONMENT === 'testing') ? $this->collectVars($exception, $statusCode)  : '';

== Modify to ==

$data = (**CI_DEBUG** || ENVIRONMENT === 'development' || ENVIRONMENT === 'testing') ? $this->collectVars($exception, $statusCode)  : '';
kenjis commented 2 months ago

Thank you for reporting!

I don't understand your recommendation. What is the Internal Server Error in "ajax"? Can you show the exact whole error message?

juangws commented 2 months ago

I create an environment file wus.php in the Boot directory. Boot And in the .env file, CI_ENVIRONMENT is set to wus. env There is a problem now that "system/Debug/ExceptionHandler.php" does not work in a custom environment. So why not, use CI_DEBUG instead of ENVIRONMENT === 'development' || ENVIRONMENT === 'testing'. If there is no way to change it, I can also modify it manually. Thank you.

*I don't know much English. I use Google Translate. I hope it won't cause you any trouble. Thank you.

kenjis commented 2 months ago

I think "system/Debug/ExceptionHandler.php" works. If ENVIRONMENT is not development or testing, $data will be ''.

What is the exact error?

kenjis commented 2 months ago

By the way, for what do you use wus?

juangws commented 2 months ago

Because sometimes online debugging. Customize wus.php and use IP to determine who is development and who is production. So I use wus.php to implement dynamic environment mode and Customize maintenance mode.

If there is an error in the code itself, $data should have an error message instead of an empty value. But in fact it is restricted by the environment name. Only environment name is development and production show errors. The development.php and production.php code:

// development.php
defined('CI_DEBUG') || define('CI_DEBUG', true);
// production.php
defined('CI_DEBUG') || define('CI_DEBUG', false);

What is its function and purpose?

So it doesn't matter whether I customize the environment mode or not. Why not make good use of CI_DEBUG to differentiate?

kenjis commented 2 months ago

My question is, what is the Internal Server Error in "ajax"? I don't think Internal Server Error should happen.

kenjis commented 2 months ago

What is its function and purpose?

CI_DEBUG is now used for Kint and Debug Toolbar. https://codeigniter4.github.io/CodeIgniter4/testing/debugging.html#enabling-kint https://codeigniter4.github.io/CodeIgniter4/testing/debugging.html#enabling-the-toolbar

kenjis commented 2 months ago

If there is an error in the code itself, $data should have an error message instead of an empty value. But in fact it is restricted by the environment name. Only environment name is development and production show errors.

Yes. https://github.com/codeigniter4/CodeIgniter4/blob/f2e560f90c88cc82964f7b5f44819bd47ee4f323/system/Debug/ExceptionHandler.php#L78-L83

At least, it matches the description in the user guide.

By default, CodeIgniter will display a detailed error report with all errors in the development and testing environments, and will not display any errors in the production environment. https://codeigniter4.github.io/CodeIgniter4/general/errors.html#error-reporting

kenjis commented 2 months ago

@codeigniter4/core-team In the current implementation, there is a difference in the conditions for displaying detailed error reports.

juangws commented 2 months ago

Thank you very much for your patience in replying. This issue is just a suggestion. I will follow https://codeigniter4.github.io/CodeIgniter4/general/errors.html#error-reporting to complete my project.

kenjis commented 2 months ago

Your suggestion has a valid point. At least, the current behaviors are difficult to understand. I think CI4 should be simple as possible.

Therefore I think one of the following would be better.

kenjis commented 2 months ago

I sent PR #9144

kenjis commented 2 months ago

Closed by #9144 in v4.6.