CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

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

Open juangws opened this issue 1 year ago • 12 comments

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)  : '';

juangws avatar Aug 14 '24 06:08 juangws

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?

kenjis avatar Aug 17 '24 02:08 kenjis

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.

juangws avatar Aug 19 '24 02:08 juangws

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

What is the exact error?

kenjis avatar Aug 19 '24 04:08 kenjis

By the way, for what do you use wus?

kenjis avatar Aug 19 '24 04:08 kenjis

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?

juangws avatar Aug 19 '24 06:08 juangws

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

kenjis avatar Aug 19 '24 07:08 kenjis

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 avatar Aug 19 '24 07:08 kenjis

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 avatar Aug 19 '24 07:08 kenjis

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

  • HTML: whether display_errors is on
  • Non HTML (API): whether ENVIRONMENT is development or testing

kenjis avatar Aug 19 '24 07:08 kenjis

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.

juangws avatar Aug 19 '24 08:08 juangws

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.

  • use display_errors in both (HTML and Non-HTML)
  • use CI_DEBUG in both

kenjis avatar Aug 19 '24 08:08 kenjis

I sent PR #9144

kenjis avatar Aug 23 '24 06:08 kenjis

Closed by #9144 in v4.6.

kenjis avatar Sep 06 '24 01:09 kenjis