Improve error messages reported to the client.

This resolves #252.