Allamah Isfaraini (Rahimahullah), the teacher of Imam Ghazali (Rahimahullah) supplicated for thirty years to Allah to make him sinless. He wanted to be completely free from all types of sin. This was a special status he sought. Only the one who does not want to displease Allah can make such a dua. One day he thought that although he had been supplicating for thirty years, Allah had not accepted his dua despite being Karim (generous in giving).
A voice emanated from the sky saying, “O Isfaraini, you want to become sinless when I have made two paths for becoming a wali. One is the path of piety and the other the path of repentance. Have you not recited the verse in the Quran wherein Allah says that He loves those who repent. When there are two windows, why are you specifying one? If due to human weakness, you commit a sin, come in close proximity to Me by repenting. Do not commit sins intentionally. When there is excessive mud, even an elephant can slip. Therefore, if you commit a sin, repent and become My beloved. Why do you only want to come via the route of piety when I have opened the door of repentance as well? When I have opened two doors, why are you appointing only one for yourself? Become My beloved via the path of repentance. Supplicate for protection from sin, not for becoming sinless.”
If you commit a sin, do not delay in repenting. Go all out in refraining from sin.
From the book A life of piety by Maulana Hakeem Akhtar (db)