Riyad as-Salihin
Anas (May Allah be pleased with him) reported that: The Messenger of Allah (ﷺ) said, "Let not one of you wish for death because of a misfortune which befalls him. If he cannot help doing so, he should say: 'O Allah, keep me alive as long as You know that life is better for me, and make me die when death is better for me".
[Al- Bukhari and Muslim].
- وعن أنس رضي الله عنه قال: قال رسول الله صلى الله عليه وسلم : " لا يتمنين أحدكم الموت لضر أصابه، فإن كان لابد فاعلاً فليقل: اللهم أحيني ما كانت الحياة خيراً لي وتوفني إذا كانت الوفاة خيراً لي" ((متفق عليه)) .
Reference