Fix write verification before we attempt to read, or throw invalid errormessage

Discovered by Coverity
Merge Pull Request #327 into next

* pr/327:
  Fix write verification before we attempt to read, or throw invalid errormessage