Log errors correctly (review by @smn and @jerith).