Fix incorrect logs under error conditions