Craig Brass Systems Forum: Debugging Help - Craig Brass Systems Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Debugging Help Help us fix any bugs you encounter

#1
User is offline   Andrew Gillard 

  • Staff - Lead Developer
  • Pip
  • Group: Developers
  • Posts: 97
  • Joined: 04-March 07
  • Gender:Male
  • Location:Basingstoke, United Kingdom
If you're finding PHP errors in the API, add this code to your API client before you include the 'integrationapi/lib/api.class.php' file:

function cbsApiErrorHandler($no, $str, $file, $line) {
    $type = 'Unknown';
    switch ($no) {
        case 1: $type = 'Fatal'; break;
        case 2: $type = 'Warning'; break;
        case 4: $type = 'Parse'; break;
        case 8: $type = 'Notice'; return; break;
        case 256: $type = 'User Error'; break;
        case 512: $type = 'User Warning'; break;
        case 1024: $type = 'User Notice'; return; break;
        case 2048: $type = 'Strict'; return; break;
        case 4096: $type = 'Recoverable'; break;
    }
    echo "<pre style=\"border:red;background:#faa;\">ERROR #$no ($type): '$str' on line $line of '$file'\r\nBacktrace:\r\n";
    debug_print_backtrace();
    echo "</pre>";
}
set_error_handler('cbsApiErrorHandler');

It will print out a red error box for each PHP error that occurs (ignoring notices and strict errors, because there are dozens of them in the Kayako code that we can't fix), and include a backtrace, showing all of the functions that were called to get to where the error occurred. The backtrace will also include the values of any parameters passed, so you will probably want to read through it to ensure that it doesn't contain any passwords before you post it here. However, posting it on this forum along with your bug report (including as much detail as you can about how the error occurred and what you were doing to cause it) will greatly help us pinpoint the problem and get it fixed quickly.

Once the problem has been resolved, you can remove the code, and you certainly shouldn't keep the error handler enabled in production sites, or you will be potentially displaying all that information to whoever visits your site. You can easily modify that code to write the result to a file instead of echoing it to the browser, though.

Thank you for your cooperation.
Andrew Gillard
Lead Developer - Craig Brass Systems
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users