Don't call the callback twice on error (fixes #347)