Adjusted error handling to avoid breaking the logger.