Sometimes debuging Drupal can get confusing. I blame the lack of oop (we want you so bad Drupal 7) , the lack of mvc, and some kind of evil gnomes plans to take over the world (but more on this latter).
So in case you’re going crazy trying to figure out what goes wrong in some otherwise great Dru[pal module, here’s little function i got from an interesting article on lulabot about debugging Drupal:
function drupal_set_message($message = NULL, $type = ‘status’)
{
// DEBUG: Go track down that stinkin’ error…
if ($type == ‘error’)
{
$message .= ‘<pre>’. print_r(debug_backtrace(), 1) .'</pre>’;
}
if ($message) {
…