ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

UhOh! - Better Errors for CodeIgniter

July 15, 2010 2:55pm

Subscribe [18]
  • #16 / Aug 04, 2010 10:48pm

    James McMurray

    23 posts

    I believe I found the problem. I installed Auth on my server at home and did the same setup as I’d done at work and it gave me the same error. I had malformed hook setups, inadvertently combining the two into a single array. What fixed the problem was switching to:

    // This is required to load the Exceptions library early enough
    $hook[‘pre_system’] = array(
      ‘function’ => ‘load_exceptions’,
      ‘filename’ => ‘uhoh.php’,
      ‘filepath’ => ‘hooks’);
     
    //Auth stuff here
    $hook[‘pre_controller’] = array(
      ‘class’  => ‘Auth_filter’,
      ‘function’ => ‘before’,
      ‘filename’ => ‘Auth.php’,
      ‘filepath’ => ‘hooks’,
      ‘params’  => array()
    );

  • #17 / Nov 09, 2010 9:02am

    Ira Rainey

    1 posts

    Brilliant. Makes debugging much easier. Thanks.

  • #18 / Dec 29, 2010 5:50pm

    TaylorOtwell

    43 posts

    Awesome library!

  • #19 / Jan 25, 2011 2:15am

    rockbust

    2 posts

    i won’t use this for the same reason i don’t buy paper towels: because i don’t make mistakes. just kidding, nice library 😊

    Doug, I am surprised you are still posting here after ripping off my $500. This money could have went to an honest programmer. Never to late to fix the situation.
    http://ellislab.com/forums/viewthread/170501/#812425

  • #20 / Jan 25, 2011 1:05pm

    paulipv

    26 posts

    Good job.
    10+

  • #21 / Feb 01, 2011 3:30pm

    SevenZark

    4 posts

    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 / Feb 26, 2011 9:12pm

    demogar

    55 posts

    Just a minor note, had to edit

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

    Using CI 2.0

  • #23 / Feb 26, 2011 9:24pm

    Dan Horrigan

    342 posts

    Ya, I need to update it for CI 2.0.  Will do it soon.

  • #24 / Feb 27, 2011 7:05am

    pmsfo

    13 posts

    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::shutdown_handler()


    Can you Help Me

    Best Regards

    Pedro Oliveira

    http://www.newitperson.com

  • #25 / Mar 01, 2011 8:45pm

    Jelenik

    9 posts

    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:

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

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

    So I had to change constructor to this:

    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:

    // 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 😊

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

  • #26 / Mar 04, 2011 11:11am

    whobutsb

    126 posts

    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::shutdown_handler()


    Can you Help Me

    Best Regards

    Pedro Oliveira

    http://www.newitperson.com

    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 / Mar 25, 2011 1:39pm

    amccausl

    1 posts

    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::shutdown_handler()


    Can you Help Me

    Best Regards

    Pedro Oliveira

    http://www.newitperson.com

    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.

    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_Exceptions:show_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 / Apr 12, 2011 8:18am

    propo

    1 posts

    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::shutdown_handler()


    Can you Help Me

    Best Regards

    Pedro Oliveira

    http://www.newitperson.com

    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.

    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_Exceptions:show_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));

    works for me, thanks amccausl

  • #29 / May 11, 2011 7:59pm

    Juventus18

    1 posts

    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.

  • #30 / Sep 01, 2011 5:06pm

    khavayero

    14 posts

    Hello,

    I’m getting the same error. I fixed it with:

    file:  /application/core/MY_Exceptions.php
    Method: show_error
    Line Aprox: 490-500

    add code:

    if (is_array($message)){
       $message = implode('<br>',$message);
    }
                 
    self::exception_handler(new ErrorException($message, E_ERROR, 0, $file, $line));
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases