I came across this in the morning and thought it was interesting, especially verses 71, 75-77. Sometimes we can lose sight of that in the midst of a trial. God allows things in our lives that would give us the opportunity to trust in Him and lean on His Word. He allows affliction in our lives because He loves us and wants our faith to be perfected in Him. I take comfort in knowing that even in the midst of a difficult trial, God is here and He loves me and has presented me with an opportunity to grow in Him.
As much as I may not like certain things, as difficult as they may be, I'm not sure my faith would develop as well if I didn't have them. There are things that need to be developed in me and it seems like trials are the only way to do that. As a diamond needs pressure to develop, so do I. Perhaps this is why the Bible speaks so much about gold refined in the fire (See Revelation 3:18-22 for one example).
65 Thou hast dealt well with thy servant, O LORD, according unto thy word.
66 Teach me good judgment and knowledge: for I have believed thy commandments.
67 Before I was afflicted I went astray: but now have I kept thy word.
68 Thou art good, and doest good; teach me thy statutes.
69 The proud have forged a lie against me: but I will keep thy precepts with my whole heart.
70 Their heart is as fat as grease; but I delight in thy law.
71 It is good for me that I have been afflicted; that I might learn thy statutes.
72 The law of thy mouth is better unto me than thousands of gold and silver.
73 Thy hands have made me and fashioned me: give me understanding, that I may learn thy commandments.
74 They that fear thee will be glad when they see me; because I have hoped in thy word.
75 I know, O LORD, that thy judgments are right, and that thou in faithfulness hast afflicted me.
76 Let, I pray thee, thy merciful kindness be for my comfort, according to thy word unto thy servant.
77 Let thy tender mercies come unto me, that I may live: for thy law is my delight.
78 Let the proud be ashamed; for they dealt perversely with me without a cause: but I will meditate in thy precepts.
79 Let those that fear thee turn unto me, and those that have known thy testimonies.
80 Let my heart be sound in thy statutes; that I be not ashamed.
(Psalm 119:65-80, emphasis mine)
But I believe the key here is that we trust. We must, especially in times of trial, lean fully upon the Lord.
Unless thy law had been my delights, I should then have perished in mine affliction. (Psalm 119:92)
I am thine, save me: for I have sought thy precepts. (Psalm 119:94)
The Psalmist doesn't ask the Lord to save him because he's done what he thought was best, rather the Psalmist cries out to God to save him solely because he is the Father's. When we seek the Lord and do His will, even when it doesn't seem to make sense to the world, we can take comfort in knowing He can and will save us. It may not be in our flesh we are saved, but if we are truly His then we are safe. We must delight ourselves in Him, in His Word.
The Word is food to our souls, if we don't eat we starve, in the same way if we don't study and dive into His Word when trouble comes it is very likely our soul will perish, our faith may falter if we do not have our feet on steady ground. And the Word is that ground. We can rest easy upon His Word, because He is perfect, faithful, and true. If His Word says He will save us, then we must rejoice! Our Redeemer lives!