[(Genesis 43:14:) "And may God Almighty grant you mercy."] This is what Scripture says (Psalms 94:12): "Blessed is the man whom You chastise, O LORD, and whom You teach from Your Torah." What is the meaning of "Blessed is the man"? Rabbi Yehoshua said: If chastisements have come upon you, and you were able to occupy yourself with Torah, they are chastisements of love; but if you were not able to occupy yourself with Torah, they are chastisements of rebellion. "Blessed is the man whom You chastise, O LORD, and whom You teach from Your Torah." Rabbi Bisna said: There is no person in the world who does not come to suffering. Thus a person who suffers in his eye cannot sleep, and one who suffers in his tooth cannot sleep, but rather he is awake the whole night; and a person who is awake the whole night and occupies himself with Torah — this one is awake and that one is awake. Hence: Happy is the man whose sufferings are in Torah.
Chastisements of Love and the Blessing of Suffering in Torah
Midrash Tanchuma Buber, Miketz 16:1
[ואל שדי יתן לכם רחמים]. זש"ה אשרי הגבר אשר תיסרנו יה ומתורתך תלמדנו (תהלים צד יב), מהו אשרי הגבר, אמר ר' יהושע אם באו עליך יסורין והייתה יכול ליגע בתורה, יסורין של אהבה הן, ואם לא הייתה יכול ליגע בתורה, יסורין של מרדות הן. אשרי הגבר אשר תיסרנו יה ומתורתך תלמדנו, אמר ר' ביסנא אין אדם בעולם שאינו בא לידי יסורין, הוי אדם חושש בעינו אינו יכול לישן, בשינו אינו יכול לישן, אלא ער כל הלילה ואדם ער כל הלילה ויגע בתורה, זה ער וזה ער, הוי אשרי אנוש שיסוריו בתורה.