Obstacles will appear on your path no matter how prepared you are. In most cases, obstacles and "failures" are actually opportunities.
Always consider the “why?” If you're asked to build a bridge across a river and you ask why you need to build a bridge, questioning why a bridge can help open up further possibilities (why do you need to cross the river? what kind of materials are available, etc.). Asking these questions will open up a realm of possibilities.
Another method is to ask yourself what you've learned from a supposed "failure." What would you do differently next time? What factors combined to cause the "failure" to happen? Was failing really as bad as you
feared?