Bad outcomes are inevitable. How we handle them makes all the difference.
There are several problem solving techniques scattered through the pages of books and across the internet that can help. Search for “The 5 Whys” and “First Principles”. Both of these methods can help us deep dive into an issue and discover the root of the problem.
What happens when you find the root is a moral problem and not a systematic one?
We cannot see the future but we can study the past. We will never go wrong, regardless of the immediate consequences, by doing what is morally right.
And it came to pass, when his master heard the words of his wife, which she spake unto him, saying, After this manner did thy servant to me; that his wrath was kindled.  And Joseph’s master took him, and put him into the prison, a place where the king’s prisoners were bound: and he was there in the prison.Genesis 39:19-20 KJV