Better error handling.

Error messages could potentially leak information. This commit ensures that only
expected error messages are actually forwarded to the user. Any unexpected
errors are logged.