Welcome Guest, Not a member yet? Register   Sign In
Error Handling Bug
#1
Bug 

I started running into weird behavior on errors on my latest CodeIgniter projects.
Errors that should be notice level, such as a field in array not found are coming up as "Critical" errors and stopping execution when in development mode and are not logged in production mode. Also rather than a normal error message that tells me where the actual error was, there's a trace with the actual location of the error buried in the middle of it.
When running database queries the behavior does not match the documentation (https://codeigniter.com/user_guide/datab...eries.html). When there's an error it immediately treats it as a fatal error. Even when I put it inside a Try-Catch it acts like the try-catch is not there and immediately produces a fatal error. The documentation says $db->query should return false $db->error can be used to handle and log the errors without the execution being stopped.
I think this worked properly on another server, but the current servers I'm using (running PHP 7.4+) seem to have something in there bypassing normal error handling and making it hard to develop and debug. I'm using 4.1.9, but tried 4.1.1 and 4.1.5 and had the same issues.
Does anyone know if there is a setting somewhere that is causing this? Is there an easy way of removing the error handling that is overriding standard PHP behavior?
Reply
#2

(This post was last modified: 06-01-2022, 09:46 PM by kenjis.)

Quote:By default, CodeIgniter will display all errors in the development and testing environments, and will not display any errors in the production environment. You can change this by setting the CI_ENVIRONMENT variable in the .env file.
https://codeigniter.com/user_guide/gener...figuration

Quote:Errors that should be notice level, such as a field in array not found are coming up as "Critical" errors and stopping execution when in development mode and are not logged in production mode.

It is the normal behavior of CI4.
In development mode, all errors stop execution.
In production mode, E_NOTICE is not reported.
See https://github.com/codeigniter4/CodeIgni...on.php#L11

(06-01-2022, 01:57 PM)Chris_otg Wrote: When running database queries the behavior does not match the documentation (https://codeigniter.com/user_guide/datab...eries.html). When there's an error it immediately treats it as a fatal error. Even when I put it inside a Try-Catch it acts like the try-catch is not there and immediately produces a fatal error. The documentation says $db->query should return false $db->error can be used to handle and log the errors without the execution being stopped.

When you set DBDebug to true, CI4 shows errors.
https://codeigniter.com/user_guide/datab...-of-values

But if you write a Try-Catch, you can catch the exception.
Reply
#3
Bug 
(This post was last modified: 06-07-2022, 11:36 AM by Chris_otg.)

Quote:In development mode, all errors stop execution.

In production mode, E_NOTICE is not reported.

So your saying the changing the error level on all exceptions to critical and stopping execution is a intentional bug?

Quote:When you set DBDebug to true, CI4 shows errors.
https://codeigniter.com/user_guide/datab...-of-values

But if you write a Try-Catch, you can catch the exception.


With database errors, both the behavior that is supposed to happen according to the documentation (the query returning fals) a and try-catches are over ridden by the instant change to a script stopping error. This happens with both dev and production settings. The only difference is the production settings cause that whoops page to be displayed. Graceful failure and error handling is not possible.

Anyone have any simple fixes for this or a way to get it back to the CI3 style of error logging which allowed graceful handling of these errors along with better log messages?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB