If an error occurs in PHP code in a node or a block then you typically get an error message like this:
Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\drupal\drupal-6.x-dev\includes\common.inc(1537) : eval()'d code on line 3
While not as crucial as this issue http://drupal.org/node/168812 (Add useful error reporting for db_query() (or add backtraces to watchdog)), something similar in the case of drupal_eval() would be much more informative, and also potentially preventing some support requests in forums and issue tracker.
It seems that depending on the specific error, an error occurring in drupal_eval() can cause cron to fail, e.g. http://drupal.org/node/184665. Would be great if this could be trapped. It seems to be the case that while some errors occurring in drupal_eval() get trapped by the Drupal error handler (e.g. divide by zero) and so will be logged in the usualy way even during a cron run, others don't seem to e.g. parse errors, calls to undefined functions (Fatal error: Call to undefined function ...
). These are the ones that I think hose cron.
Comments
Comment #1
EgbertB CreditAttribution: EgbertB commentedTo add some gravity to this feature request: These kinds of sometimes intraceable errors can also stop your site from being indexed by mother Google.
Comment #2
markshust CreditAttribution: markshust commentedbumping this. these errors caused my log files to grow to over 5gb and haulted backups on a production site.
Comment #3
drinkingcoffee CreditAttribution: drinkingcoffee commentedI also think this would be pretty useful. Tracing the source of these errors can be an extremely difficult task, especially if there is a lot of PHP code being eval'd throughout the site (on blocks, views, etc...).
I recently encountered this problem and had a tough time finding the source of the problem.
In the end, I dumped all the PHP code from the database into a php file and executed it manually from the command-line.
The source of all these troubles? code which was emailed, then copy-pasted into the textareas. Apparently the mail client inserted some (invisible) tab characters which were causing eval() to die.
Perhaps instead of better error reporting, it would be better to do some extra syntax validation on the PHP code when a form is submitted? That way, we'd be able to prevent invalid code from being stored to the DB at all.
I'd have to think this through, but I think it would be possible to do something like:
eval("if(0){".$submittedCode."})
There are some examples in the comments of the php.net documentation.