Jump to content



Photo
- - - - -

KissER Error Handling & Debugging [contribution]


  • Please log in to reply
172 replies to this topic

#1   FWR Media

FWR Media
  • Members
  • 6,839 posts
  • Real Name:Robert Fisher
  • Gender:Male
  • Location:Stowmarket - Suffolk - UK

Posted 28 January 2010 - 15:00

KissER Error Handling & Debugging

a KISS contribution ( Keep It Simple Stupid )

Compatibility:
osCommerce ( MS2.2/RC ALL )
PHP5.2+/5.3+ ( PHP 4 NOT supported )

Installation:
Simple 2-3 minutes

Potential code conflicts:
Effectively none the one exception would be if the tep_db_query() function had been modified for Chemos old query debug.

What is it and what will it do for me?

Main Benefits:

  • Would you like to be able to find and handle errors that your site is currently hiding/suppressing?
  • Would you like to have a file to check to see if your site has any errors while at the front end the users see nothing?
  • Ever been developing a site and would like to see errors without them breaking up the page?
  • Ever wanted to look for errors but don't want to "turn up" the error reporting because users would see them?
  • Ever wanted to show a new client just how many errors their current osCommerce site has but they can't see?
  • Would you like to stop errors from printing out full paths in view of the hacking world?
  • Would you like to easily be able to debug: queries, variables, arrays, objects or site slowdowns?

Gracefull Error Handling:
Disclaimer: Some PHP errors like parse errors and fatal errors can NOT be handled gracefully.

osCommerce has nothing in place at all to deal with errors, either you suppress errors ( error_reporting ( E_ALL & ~E_NOTICE ) ) which is the standard osCommerce set up. Or you set error reporting high ( error_reporting ( E_ALL | E_STRICT ) ) and the site falls apart with errors all over the shop. ( obviously not possible on a live site ).

Understandably because of this the vast majority of osCommerce installations suppress all errors. What this means is that most osCommerce installations have tons of errors but the owners of the sites are happily ignorant of this fact. You will probably be surprised to know that some shops even suppress warnings, terrible!

Also, when errors print to screen via standard PHP error handling they show your servers full path which is a potential serious security risk, KissER suppresses these full paths.

There are those ( usually contributors of dodgy contributions or incapable developers ) who would tell you "don't worry about those, they are only notices .. they're fine!", rubbish!, errors are errors and a good shop should have none. An error free shop will be faster, more secure and easier to debug. Ignore errors at your peril!

Think your site is error free? I very much doubt it!

But the last thing I want my users to see is errors!!

Agreed .. which is why KissER Error Handling & Debugging has settings where these errors can be printed to screen but only visible to you, or silently written to an error file where you can view and handle them at your leisure.

Debugging:

Powerful set of simple to use debugging tools where you can easily debug: -

  • queries
  • variables
  • arrays
  • objects

You can also use "break points" to locate where a site is slowing down or breaking.

Download the current version

Edited by FWR Media, 28 January 2010 - 15:01.


#2   moezbud

moezbud
  • Members
  • 55 posts
  • Real Name:Moez

Posted 03 February 2010 - 10:52

Unfortunately, I'm not much of a PHP programmer... so, this may be a dumb question.

Is there any way to make this compatable with PHP 4.xx?

Thanks!

Edited by moezbud, 03 February 2010 - 10:53.


#3   FWR Media

FWR Media
  • Members
  • 6,839 posts
  • Real Name:Robert Fisher
  • Gender:Male
  • Location:Stowmarket - Suffolk - UK

Posted 03 February 2010 - 10:57

Unfortunately, I'm not much of a PHP programmer... so, this may be a dumb question.

Is there any way to make this compatable with PHP 4.xx?

Thanks!


No sorry. I have no interest in supporting PHP 4, it is dead and gone.

#4   modem2.0

modem2.0
  • Members
  • 70 posts
  • Real Name:Modem 2.0

Posted 03 February 2010 - 16:58

I Robert,

Thanks for this awesome contribution, keep up the good work.
In the installation you say for application_top.php file

Find ( near the top ) ...
// set the level of error reporting
  error_reporting(E_ALL & ~E_NOTICE);

Replace with ...
// set the level of error reporting
  error_reporting(E_ALL & ~E_NOTICE);

  // KISS Error Handling & Debugging by FWR Media 
  include_once 'includes/kiss_error_handler.php';
I mean, you are saying to replace error_reporting(E_ALL & ~E_NOTICE); with the same code. Is this a bug? Did you want to say something else or it is correct?

#5   FWR Media

FWR Media
  • Members
  • 6,839 posts
  • Real Name:Robert Fisher
  • Gender:Male
  • Location:Stowmarket - Suffolk - UK

Posted 03 February 2010 - 17:13

I Robert,

Thanks for this awesome contribution, keep up the good work.
In the installation you say for application_top.php file

Find ( near the top ) ...
// set the level of error reporting
  error_reporting(E_ALL & ~E_NOTICE);

Replace with ...
// set the level of error reporting
  error_reporting(E_ALL & ~E_NOTICE);

  // KISS Error Handling & Debugging by FWR Media 
  include_once 'includes/kiss_error_handler.php';
I mean, you are saying to replace error_reporting(E_ALL & ~E_NOTICE); with the same code. Is this a bug? Did you want to say something else or it is correct?


Hi

May look odd but it is correct.

I find people make less mistakes when you "replace" code rather than "add above" or "add below".

It certainly isn't a bug as it just replaces the same code and adds a bit below.

E.g. if you hadn't actually looked at the code you would have simply replaced the one with the other. Had it been an "add below" you would have had to think about it.

Edited by FWR Media, 03 February 2010 - 17:15.


#6   sijo

sijo
  • Members
  • 268 posts
  • Real Name:Stein Ivar Johnsen
  • Gender:Male
  • Location:Norway

Posted 03 February 2010 - 23:44

Think your site is error free? I very much doubt it!

Download the current version


You are sooooo right..[img]http://forums.oscommerce.com/public/style_emoticons/default/crying.gif[/img]

I'm now using this contribution and it is very helpful when I try to get rid of all errors, and that's NOT one or two..
---------------
regards
sijo
---------------

Contrib: JMrating10 - Rate your products  /  osCommerce VTS - Virus & Threat Scanner

(osCommerce VTS now also checks for leading and trailing whitespace and also have a grep function)

#7   modem2.0

modem2.0
  • Members
  • 70 posts
  • Real Name:Modem 2.0

Posted 06 February 2010 - 21:48

You are sooooo right..[img]http://forums.oscommerce.com/public/style_emoticons/default/crying.gif[/img]

I'm now using this contribution and it is very helpful when I try to get rid of all errors, and that's NOT one or two..

I agree... I even found that the total module cash on delevery with fee was not deleting all the keys when pressing the remove module name. I had 2 keys 9 times each in the database...

#8   FWR Media

FWR Media
  • Members
  • 6,839 posts
  • Real Name:Robert Fisher
  • Gender:Male
  • Location:Stowmarket - Suffolk - UK

Posted 06 February 2010 - 22:27

Well this is nice early feedback .. seems people are enjoying it or at least finding it useful.

What I find with contributions like this and Security Pro is they don't tend to get noticed unless people have problems.

#9   Stealth1

Stealth1
  • Members
  • 338 posts
  • Real Name:Chris

Posted 09 February 2010 - 05:25

Is it recommended to remove the install of Chemo's query mod before installing this?

#10   FWR Media

FWR Media
  • Members
  • 6,839 posts
  • Real Name:Robert Fisher
  • Gender:Male
  • Location:Stowmarket - Suffolk - UK

Posted 09 February 2010 - 07:52

Is it recommended to remove the install of Chemo's query mod before installing this?


Yes, the code in the tep_db_query() function may conflict.

#11   bonester1981

bonester1981
  • Members
  • 13 posts
  • Real Name:Thomas

Posted 09 February 2010 - 20:06

Hi,
I am testing this contribution and find it very useful. I like your contribs, thanks for that! /smile.gif' class='bbc_emoticon' alt=':)' />

Everything works fine, except this:

Error: Undefined index: break
File: includes/kiss_error_handler.php
Line: 316
E_WARNING Error Count: 1
Error: Invalid argument supplied for foreach()
File: includes/kiss_error_handler.php
Line: 316

My configuration:
PHP Version 5.2.12
Linux

Kind regards

#12   FWR Media

FWR Media
  • Members
  • 6,839 posts
  • Real Name:Robert Fisher
  • Gender:Male
  • Location:Stowmarket - Suffolk - UK

Posted 09 February 2010 - 20:33

Hi,
I am testing this contribution and find it very useful. I like your contribs, thanks for that! /smile.gif' class='bbc_emoticon' alt=':)' />

Everything works fine, except this:

Error: Undefined index: break
File: includes/kiss_error_handler.php
Line: 316
E_WARNING Error Count: 1
Error: Invalid argument supplied for foreach()
File: includes/kiss_error_handler.php
Line: 316

My configuration:
PHP Version 5.2.12
Linux

Kind regards


Interesting .. KissER reporting itself for errors /rolleyes.gif' class='bbc_emoticon' alt=':rolleyes:' />

catalog/includes/kiss_error_handler.php

Line 76 should be ..

private static $breakpoints = array( 'break' => array() );


#13   Stealth1

Stealth1
  • Members
  • 338 posts
  • Real Name:Chris

Posted 10 February 2010 - 06:30

Installed and working great! another amazing contribution FWR!

Guessing I should start a seperate thread to get help on fixing the errors I have

#14   sijo

sijo
  • Members
  • 268 posts
  • Real Name:Stein Ivar Johnsen
  • Gender:Male
  • Location:Norway

Posted 10 February 2010 - 14:13

I'm getting too much E_NOTICE errors filling up the log-file, so I made a litle switch:

On top of catalog/includes/kiss_error_handler.php:

define('KISS_ERROR_REPORTING_SKIP', 'E_NOTICE');

Around line 279 I have made this changes:

if ($error_type <> KISS_ERROR_REPORTING_SKIP) {
$error_string = 'Date / Time: ' . date("d-m-Y H:i:s") . PHP_EOL;
$error_string .= 'Error Type: [' . $error_type . '] ' . $detail['string'] . PHP_EOL;
$error_string .= 'On line ' . $detail['line'] . PHP_EOL . 'File ' . $detail['file'] . PHP_EOL;
$error_string .= str_repeat( '-+', 30 ) . PHP_EOL . PHP_EOL;
$this->writeToFile( $error_string );
}

Is this ok, or do you have a better way to do this? (It is working)
---------------
regards
sijo
---------------

Contrib: JMrating10 - Rate your products  /  osCommerce VTS - Virus & Threat Scanner

(osCommerce VTS now also checks for leading and trailing whitespace and also have a grep function)

#15   FWR Media

FWR Media
  • Members
  • 6,839 posts
  • Real Name:Robert Fisher
  • Gender:Male
  • Location:Stowmarket - Suffolk - UK

Posted 10 February 2010 - 14:30

I'm getting too much E_NOTICE errors filling up the log-file, so I made a litle switch:

On top of catalog/includes/kiss_error_handler.php:

define('KISS_ERROR_REPORTING_SKIP', 'E_NOTICE');

Around line 279 I have made this changes:

if ($error_type <> KISS_ERROR_REPORTING_SKIP) {
$error_string = 'Date / Time: ' . date("d-m-Y H:i:s") . PHP_EOL;
$error_string .= 'Error Type: [' . $error_type . '] ' . $detail['string'] . PHP_EOL;
$error_string .= 'On line ' . $detail['line'] . PHP_EOL . 'File ' . $detail['file'] . PHP_EOL;
$error_string .= str_repeat( '-+', 30 ) . PHP_EOL . PHP_EOL;
$this->writeToFile( $error_string );
}

Is this ok, or do you have a better way to do this? (It is working)


If the log file is filling up then you really shouldn't be logging the errors to file. The log file is there for when you are just about error free and you want to find any errors that crop up over time.

If you are still working on the errors then use the screen method but remember to set ..

KISS_ERROR_REPORTING_GET_SWITCH

This way only you will see the errors printed to screen.

#16   erikesq777

erikesq777
  • Members
  • 3 posts
  • Real Name:Erik

Posted 10 February 2010 - 22:10

I saw my error after posting this message.

Thanks

Edited by erikesq777, 10 February 2010 - 22:13.


#17   richcduk

richcduk
  • Members
  • 14 posts
  • Real Name:rich

Posted 12 February 2010 - 13:53

Awsome contibution. Best yet ! no more scratching of head !!! /thumbsup.gif' class='bbc_emoticon' alt=':thumbsup:' />

#18   parksey

parksey
  • Members
  • 40 posts
  • Real Name:Rhys

Posted 13 February 2010 - 02:13

Hi Rob

Great Contrib !! And thanks for sharing.

But should I really go through and fix all undefined variable errors? most people just knock down the reporting level to ignore these?

cheers

rhys

#19   FWR Media

FWR Media
  • Members
  • 6,839 posts
  • Real Name:Robert Fisher
  • Gender:Male
  • Location:Stowmarket - Suffolk - UK

Posted 13 February 2010 - 07:51

Hi Rob

Great Contrib !! And thanks for sharing.

But should I really go through and fix all undefined variable errors? most people just knock down the reporting level to ignore these?

cheers

rhys


Errors are errors. You are right, most people just knock down the error reporting "what I can't see can't hurt me", this is a very bad practice, errors should never be ignored.

Error free sites are more secure, easier to debug and faster. Undefined variables show shoddy coding and are a route to hacking.

#20   moezbud

moezbud
  • Members
  • 55 posts
  • Real Name:Moez

Posted 19 February 2010 - 20:53

I hope that this is not a dumb request.... but, what the heck - I have to admit to not being very bright when it comes to this...

I have installed this contribution and it has already helped me quite a bit. However, right now I am trying to determine logical errors. For example, I am tring to install paypal IPN and the orders are double posting on my orders table. With this, I am trying to see exactly which module is processing a given query (i.e. is it happening in checkout_confirmation.php, orders.php, general.php, etc.). I can see that all of these queries are occuring, but I'm having difficulty zeroing in on my culprit modules.

Is it possible to add a line that would show the calling module (and ideally the line) where things are happening? If so, can you give me some idea of how to do it?

Thanks!