I just reviewed someone else's code which give a cryptic error message, warning: Invalid argument supplied for foreach() in /Applications/xampp/xamppfiles/htdocs/fl/includes/common.inc on line 3164., which baffled us, as the hook_schema() implementation was fine and dandy. Until I realised he had called drupal_[un]install_schema per-table instead of per-module/hook_schema()-function. It would be great if Drupal could put a more informative error message in the place of the other message. (Perhaps something like "Error: @module_schema doesn't exist.") Perhaps PHP 5's exception handling could be used for this? (I've only played with exceptions in Python, so I don't know if PHP handles them just as easily...)

CommentFileSizeAuthor
#2 issue_255022.d7.patch2.32 KBFreso
#1 physiolog.install.txt1.7 KBmikl

Comments

mikl’s picture

StatusFileSize
new1.7 KB

Well, actually, it gives four error messages:

    * warning: Invalid argument supplied for foreach() in /Applications/xampp/xamppfiles/htdocs/fl/includes/common.inc on line 3164.
    * warning: Invalid argument supplied for foreach() in /Applications/xampp/xamppfiles/htdocs/fl/includes/common.inc on line 3110.
    * warning: Invalid argument supplied for foreach() in /Applications/xampp/xamppfiles/htdocs/fl/includes/common.inc on line 3164.
    * warning: Invalid argument supplied for foreach() in /Applications/xampp/xamppfiles/htdocs/fl/includes/common.inc on line 3085.

I've attached the .install file in question for easy reproduction.

Freso’s picture

Status: Active » Needs review
StatusFileSize
new2.32 KB

Here's a quick throw-together, untested and without tests written for it, but mostly just meant to demonstrate some try/except code in PHP. Is this something we want?

chx’s picture

Status: Needs review » Closed (won't fix)

We still do not babysit broken code. If you want to reopen this, answer with justification -- why should this code sit in memory for every single uncached Drupal page load given that unlikely rarely used code ths is code that should never fire...

mikl’s picture

Status: Closed (won't fix) » Needs work

Tested in HEAD.

Before patching, we still get errors like mention above (but only to, compared to four in 6.2)

* warning: Invalid argument supplied for foreach() in /Applications/xampp/xamppfiles/htdocs/drupal-HEAD/includes/common.inc on line 3167.
* warning: Invalid argument supplied for foreach() in /Applications/xampp/xamppfiles/htdocs/drupal-HEAD/includes/common.inc on line 3088.

After patching, I get no error messages, but nothing in the database either.

mikl’s picture

Status: Needs work » Closed (won't fix)

Oh, sorry. Race condition.

I still think that we should handle errors better. A more helpful error message would have saved me an hour banging my head against the wall, thinking myself stupid.