We make plenty of mistakes in life but God does nothing by mistake but is sovereignly working everything together in your life for your very best and for His glory.
God never makes a mistake and He even uses our mistakes for His glory and purpose. Scripture teaches that “we know that for those who love God all things work together for good, for those who are called according to his purpose” (Rom 8:28). It doesn’t say that all things are good but all things, both the good and bad, will work out for our best. Consider the cross. God was not caught off guard by Calvary because it had been foreordained for our redemption (Isaiah 53). 
Joseph’s story reminds us all that God is always in charge. He was abused by his brothers and thrown into a pit. They wanted to leave them there to die but instead, they made money off him by selling him into slavery. Later, he was unjustly thrown into prison but Joseph knew that “God meant it for good, to bring it about that many people should be kept alive, as they are today” (Gen. 50:20). By Joseph humbly submitting to the sovereignty of God, God helped Joseph to being second in command in Egypt, having all authority in Egypt, subject only to the Pharaoh. God’s sovereignly using Joseph saved the lives of much of the civilized world at that time. Joseph’s bad things brought much good to millions.
Not Without Purpose
We might think that what we’re going through doesn’t have a purpose, but God has set everything in motion for His purposes and our good (if we are saved). God has revealed that “we were also chosen, having been predestined according to the plan of him who works out everything in conformity with the purpose of his will” (Eph. 1:11). Our salvation was conformed to God’s will by God Himself, not us (Eph 2:1-5). Even when Paul was imprisoned unjustly, much like Joseph, this allowed Paul to write much of the New Testament that we have today (in the Prison Epistles). Paul even used being chained to Roman guards as an opportunity to tell them about the Gospel of Jesus Christ, so he was blessed by having a captive audience; those in jail included! Nothing in this life is ever wasted as far as God is concerned, and nothing is without purpose in the sovereignty of God.
Determining Our Faithfulness
God will sometimes use trials to reveal the strength or weakness of our faith. Jesus was speaking to His disciples at the last meal before He went to the cross, and at the Passover Meal He said, “You are those who have stayed with me in my trials, and I assign to you, as my Father assigned to me, a kingdom, that you may eat and drink at my table in my kingdom and sit on thrones judging the twelve tribes of Israel” (Luke 22:28-30). That comment by Jesus surely strengthened the disciples’ faithfulness, and it should ours too. Obviously Jesus for no reason of His own (He was without sin), so the question is: “Will we remain faithful to Him in and through our trials, or will we bail out at the first sign of trouble?”
James knew that many were experiencing severe trials, but these problems had a purpose behind them. He wrote that we should “count it all joy, my brothers, when you meet trials of various kinds, for you know that the testing of your faith produces steadfastness” (James 1:2-3), and then “let steadfastness have its full effect, that you may be perfect and complete, lacking in nothing” (James 1:4). This means we should remain steadfast, even when everything around us is going wrong. These troubles are perfecting us and shaping us and molding us into the image Christ.
The psalmist knew a lot about afflictions, and must have known why God allowed some of them. He wrote, “It is good for me that I was afflicted, that I might learn your statutes” (Psalm 119:71). These afflictions made him learn more about God’s statutes and kept him in the Word of God, saying “Before I was afflicted I went astray, but now I keep your word” (Psalm 119:67). Affliction can do that…believe me.
God will sometimes allow a problem for the purpose of perfecting us. No, we’ll never be perfect this side of heaven, but Paul saw every problem as an opportunity for God to work in us. He wrote, “Not only that, but we rejoice in our sufferings, knowing that suffering produces endurance, and endurance produces character, and character produces hope” (Rom. 5:3-4), so God never wastes any problem but uses them all for our own good (Rom. 8:28).
When we run into problems that only God can solve, they serve to humble us and bring us to our knees, but this is our rightful position anyway isn’t it? We are told, “Humble yourselves, therefore, under the mighty hand of God so that at the proper time he may exalt you” (1 Pet. 5:6). Peter’s pride likely taught him something he’ll never forget, like “For all those who exalt themselves will be humbled, and those who humble themselves will be exalted” (Luke 14:11). Either we humble ourselves or He will do it for us, and you can guess which one is more painful.
Proverbs 20:30 shows how God uses problems to help us in our growing in holiness, as it “Blows that wound cleanse away evil; strokes make clean the innermost parts.” Problems and trials can be used for our directing and our reflecting but surely our perfecting, as they “cleanse away evil” and “make clean the innermost parts.” Maybe they’re mean to bring us to repentance and confession of whatever we were doing that we ought not to have been doing.
Just as we discipline our child out of love, “the Lord disciplines the one he loves, and chastises every son whom he receives” (Heb. 12:6). Our Lord says it is for “Those whom I love, I reprove and discipline, so be zealous and repent” (Rev. 3:19). Did you catch that? He disciplines us because He loves us and wants us to repent. It is similar to child rearing where “Folly is bound up in the heart of a child, but the rod of discipline will drive it far away” (Prov. 22:15).
Our problems can act as a compass, directing us in the way we should go. Notice Jesus rebuked the church for “how far you have fallen! Repent and do the things you did at first. If you do not repent, I will come to you and remove your lampstand from its place” (Rev. 2:5). Apparently the church at Ephesus had fallen into some serious sin and Jesus wanted them to repent of it. In His rebuke, He was directing them toward repentance, which would be in their best interests anyway. 
There are trials of perfection, direction, inspection, reflection, correction and even protection, but God uses these problems to work for His good purposes for our best (Rom 8:28), so nothing that happens is an accident, but rather it is God’s sovereignty at work in your life. God will not waste anything that we experience in life, and this includes our troubles. He may want us to know how strong or weak our faith is because He already knows. Let life’s afflictions have their work in you. Don’t resist what God is allowing to happen to you because it really is the best thing for you; even if it doesn’t feel like it. Whatever the case may be, God has a purpose behind every problem. Just because we can’t see the purpose behind the problem doesn’t mean there’s no purpose behind it. Everything ever created has a purpose. Knowing God is sovereign, I know not one bit of trouble is ever wasted, but that it has a purpose for Him (His glory) and for me (even if I don’t yet know it.).
Here is some related reading for you: Why Should Christians Pray if God is Sovereign? 
Resource – Scripture quotations are from The Holy Bible, English Standard Version® (ESV®), Crossway Bibles. (2007). ESV: Study Bible: English standard version. Wheaton, Ill: Crossway Bibles. Used by permission. All rights reserved.