Welcome Guest, Not a member yet? Register   Sign In
UhOh! - Better Errors for CodeIgniter
#21

[eluser]SevenZark[/eluser]
Hi,

This looks like something I could really use, however it has a large amount of code that is hard-coded to look for 'MY_' as a subclass prefix on the Exceptions class, rather than using the subclass prefix config value. This causes problems for my app, since I have it configured to use a different subclass prefix value. Perhaps you can adapt this to use the configured value instead of a hardcoded value, and you can just explain in the readme that if the user has configured a different subclass prefix, then he/she will just need to rename the MY_Exceptions file and the class declaration within it. That's much easier to do than wade through the code and edit every occurrence of the class/file name. It also may not be a great idea to step over CI's config value for this instead of working with it. Since the system itself allows us to config this, then hard-coding it in an extension seems like a tiny step backward. Just a thought. And thanks for putting this extension together!
#22

[eluser]demogar[/eluser]
Just a minor note, had to edit

Quote:// from
parent::CI_Exceptions();
//to
parent::__construct();

Using CI 2.0
#23

[eluser]Dan Horrigan[/eluser]
Ya, I need to update it for CI 2.0. Will do it soon.
#24

[eluser]pmsfo[/eluser]
Hi I have this error.

I Using ZendServer and CI2.0


ErrorException [ Fatal Error ]: Wrong parameters for ErrorException([string $exception [, long $code, [ long $severity, [ string $filename, [ long $lineno [, Exception $previous = NULL]]]]]])

FCPATH/application\core\MY_Exceptions.php [ 492 ]

487 break;
488 }
489 }
490 unset($trace);
491
492 self::exception_handler(new ErrorException($message, E_ERROR, 0, $file, $line));
493 return;
494 }
495
496 /**
497 * Is Extension

1.

{PHP internal call} » MY_Exceptions:Confusedhutdown_handler()


Can you Help Me

Best Regards

Pedro Oliveira

www.newitperson.com
#25

[eluser]Jelenik[/eluser]
Hi Dan,

thanks for awesome hook for codeigniter.
My story:
- i wanted to have UhOh enabled on localhost, but wanted to be disabled on real server, but i also wanted to have this kind of functionality : - when there is an error and codeigniter will log it, i added that codeigniter will insert log in database table error_logs (full message with filepath and so on...)and then send me email message about it (if there wasnt row in database with exactly same message - so i wont get duplicated emails about the same error).
- i did this with this code in application/core/MY_Exceptions.php:
Code:
function log_exception($severity, $message, $filepath, $line)

        {

            $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];

            log_message('error', 'Severity: '.$severity.'  --> '.$message. ' '.$filepath.' '.$line, TRUE);

            // Send a email if there isnt this error message yet - NOT ON LOCALHOST
            if ($_SERVER['HTTP_HOST'] != 'localhost' AND $_SERVER['HTTP_HOST'] != '127.0.0.1') {
                    $CI =& get_instance();
                    $CI->load->helper('url');
                    $CI->load->database();
                    $email_message = "Message: ".$message."\nFilepath: ".$filepath." [".$line."]\nUrl: ".current_url();
                    $result = $CI->db->get_where('error_logy',array('sprava'=>$email_message));
                    if ($result->num_rows() == 0) {
                            $CI->load->library('email');
                            $CI->email->from('[email protected]', 'Bug logger');
                            $CI->email->to('[email protected]');
                            $CI->email->subject('Error on web example.com');
                            $CI->email->message($email_message);
                            $CI->email->send();
                            $CI->db->insert('error_logy',array('sprava'=>$email_message,'cas'=>date("Y-m-d H:i:s", time())));
                    }
            }
        }

but there was problem to add this in your MY_Exceptions.php, because in v1.5 you are using this code in constructor (so when we are in production, whole extension of core class Exceptions will be ignored (with my function for sending emails also)):

Code:
// If we are in production, then lets dump out now.
        if (IN_PRODUCTION)
        {
            return;
        }

So I had to change constructor to this:
Code:
public function __construct()
    {
        parent::__construct();
        
        // If we are in production do nothing
        if (IN_PRODUCTION)
        {

        }
                else {
                    //Set the Exception Handler
                    set_exception_handler(array('MY_Exceptions', 'exception_handler'));

                    // Set the Error Handler
                    set_error_handler(array('MY_Exceptions', 'error_handler'));

                    // Set the handler for shutdown to catch Parse errors
                    register_shutdown_function(array('MY_Exceptions', 'shutdown_handler'));

                    // This is a hack to set the default timezone if it isn't set. Not setting it causes issues.
                    date_default_timezone_set(date_default_timezone_get());
                }
    }

and then added to beginning of each of your function this:
Code:
// If we are in production, then lets dump out now.
        if (IN_PRODUCTION)
        {
            return;
        }

As you can see - it isnt so good, its only fast hack. But i will be more than happy if you can implement similiar functionality (email reporting of errors) to UhOh! I think it isnt so complicated - you just let user posibility to set email_reporting to TRUE and if so, they will be forced to create simple database table (just like when you are using sessions with database).

You know, i dont want to tweek every new version of your UhOh to implement that functionality Smile

What do you think about it?
Sorry for my easy english, i hope you understand.
#26

[eluser]whobutsb[/eluser]
[quote author="pmsfo" date="1298826350"]Hi I have this error.

I Using ZendServer and CI2.0


ErrorException [ Fatal Error ]: Wrong parameters for ErrorException([string $exception [, long $code, [ long $severity, [ string $filename, [ long $lineno [, Exception $previous = NULL]]]]]])

FCPATH/application\core\MY_Exceptions.php [ 492 ]

487 break;
488 }
489 }
490 unset($trace);
491
492 self::exception_handler(new ErrorException($message, E_ERROR, 0, $file, $line));
493 return;
494 }
495
496 /**
497 * Is Extension

1.

{PHP internal call} » MY_Exceptions:Confusedhutdown_handler()


Can you Help Me

Best Regards

Pedro Oliveira

www.newitperson.com[/quote]

I'm receiving this same error as well. I can view the messages when I click on Environment, it will show me an array of the error messages, but it seems like UhOh! Library is getting hung up.
#27

[eluser]Unknown[/eluser]
[quote author="whobutsb" date="1299273062"][quote author="pmsfo" date="1298826350"]Hi I have this error.

I Using ZendServer and CI2.0


ErrorException [ Fatal Error ]: Wrong parameters for ErrorException([string $exception [, long $code, [ long $severity, [ string $filename, [ long $lineno [, Exception $previous = NULL]]]]]])

FCPATH/application\core\MY_Exceptions.php [ 492 ]

487 break;
488 }
489 }
490 unset($trace);
491
492 self::exception_handler(new ErrorException($message, E_ERROR, 0, $file, $line));
493 return;
494 }
495
496 /**
497 * Is Extension

1.

{PHP internal call} » MY_Exceptions:Confusedhutdown_handler()


Can you Help Me

Best Regards

Pedro Oliveira

www.newitperson.com[/quote]

I'm receiving this same error as well. I can view the messages when I click on Environment, it will show me an array of the error messages, but it seems like UhOh! Library is getting hung up.[/quote]

I'm getting the same error. It shows up when there is an error from the database. I fixed it with a small change to MY_ExceptionsConfusedhow_error. At end, before the return line:

Replace:

self::exception_handler(new ErrorException($message, E_ERROR, 0, $file, $line));

With:

if( is_array($message) )
self::exception_handler(new ErrorException($message[1], E_ERROR, 0, $file, $line));
else
self::exception_handler(new ErrorException($message, E_ERROR, 0, $file, $line));
#28

[eluser]Unknown[/eluser]
[quote author="amccausl" date="1301089196"][quote author="whobutsb" date="1299273062"][quote author="pmsfo" date="1298826350"]Hi I have this error.

I Using ZendServer and CI2.0


ErrorException [ Fatal Error ]: Wrong parameters for ErrorException([string $exception [, long $code, [ long $severity, [ string $filename, [ long $lineno [, Exception $previous = NULL]]]]]])

FCPATH/application\core\MY_Exceptions.php [ 492 ]

487 break;
488 }
489 }
490 unset($trace);
491
492 self::exception_handler(new ErrorException($message, E_ERROR, 0, $file, $line));
493 return;
494 }
495
496 /**
497 * Is Extension

1.

{PHP internal call} » MY_Exceptions:Confusedhutdown_handler()


Can you Help Me

Best Regards

Pedro Oliveira

www.newitperson.com[/quote]

I'm receiving this same error as well. I can view the messages when I click on Environment, it will show me an array of the error messages, but it seems like UhOh! Library is getting hung up.[/quote]

I'm getting the same error. It shows up when there is an error from the database. I fixed it with a small change to MY_ExceptionsConfusedhow_error. At end, before the return line:

Replace:

self::exception_handler(new ErrorException($message, E_ERROR, 0, $file, $line));

With:

if( is_array($message) )
self::exception_handler(new ErrorException($message[1], E_ERROR, 0, $file, $line));
else
self::exception_handler(new ErrorException($message, E_ERROR, 0, $file, $line));[/quote]

works for me, thanks amccausl
#29

[eluser]Unknown[/eluser]
Will this tell you the calling function and location where the error originated? for example, if I have a model that has the line $this->db->select('field_doesnt_exist') i get an error back that says the error is in the CI DB driver. But I want it to tell me the filename/model that originated the call.




Theme © iAndrew 2016 - Forum software by © MyBB