Make some error messages more user-friendly.

Fixes #1304, #1007.