Enhanced error output logic.