Improved logic to handle attachments with errors