Improve error reporting (but it's mostly untested).