At least the user should get a slightly more useful error message now. Updates #799. Originally committed to SVN as r2998.