I heard the Prophet ﷺ say, three days before his death, "None of you should die except while holding a good opinion of Allah."
حدثنا يحيى بن آدم حدثنا سفيان عن الأعمش عن أبي سفيان
سمعت النبي ﷺ قبل موته بثلاث يقول لا يموتن أحدكم إلا وهو يحسن بالله الظن
Its chain of transmission is sahih. Abu Sufyan is Talha bin Nafi Qurashi, whom Ahmad, Nasai, and Abu Hatim approved of, while Ibn Main criticized him. Ibn Adi accepted him, particularly when well-known narrators such as Shuba and Amash transmitted from him, as is the case in this chain.The hadith was narrated by Abu Dawud, 3/484, number 3113, in the Book of Funerals, in the chapter on the recommendation of having good expectations of Allah. And by Abu Naeem in al-Hilyah, 8/121.