Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
juangws opened this issue Aug 14, 2024 · 13 comments

Comments

@juangws
Copy link

juangws commented Aug 14, 2024

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
Copy link
Member

kenjis commented Aug 17, 2024

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 kenjis added the waiting for info Issues or pull requests that need further clarification from the author label Aug 17, 2024
@juangws
Copy link
Author

juangws commented Aug 19, 2024

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
Copy link
Member

kenjis commented Aug 19, 2024

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

What is the exact error?

@kenjis
Copy link
Member

kenjis commented Aug 19, 2024

By the way, for what do you use wus?

@juangws
Copy link
Author

juangws commented Aug 19, 2024

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
Copy link
Member

kenjis commented Aug 19, 2024

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

@kenjis
Copy link
Member

kenjis commented Aug 19, 2024

@kenjis
Copy link
Member

kenjis commented Aug 19, 2024

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.

if (! str_contains($request->getHeaderLine('accept'), 'text/html')) {
$data = (ENVIRONMENT === 'development' || ENVIRONMENT === 'testing')
? $this->collectVars($exception, $statusCode)
: '';
$this->respond($data, $statusCode)->send();

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 kenjis removed the waiting for info Issues or pull requests that need further clarification from the author label Aug 19, 2024
@kenjis
Copy link
Member

kenjis commented Aug 19, 2024

@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

@juangws
Copy link
Author

juangws commented Aug 19, 2024

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
Copy link
Member

kenjis commented Aug 19, 2024

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
Copy link
Member

kenjis commented Aug 23, 2024

I sent PR #9144

@kenjis
Copy link
Member

kenjis commented Sep 6, 2024

Closed by #9144 in v4.6.

@kenjis kenjis closed this as completed Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants