Failure is a stepping stone to success only if it can teach you something. If not, then failure will be a waste of your time. Imagine that there are two children, both practicing for a running race. Child A first crosses 100 metres with record time but fails to do so for 200 metres. In the next effort, he crosses 200 metres in time, but is not able to do 300 metres. His failure is helpful because he is raising the bar higher each time. He is failing quite often, but with each effort, he is also getting better. Contrast that with child B, who never makes past 100 metres in record time. Either he does not start properly, or finish properly or lags in between.
Child B is not making any progress. He is also much more likely to be frustrated. Either he does not like running, or even if he does, does not have the ability to run. This could be because he is not practicing his starting and ending techniques properly before making the run. All of this means that each time he fails to cross 100 metres in record time, is a redundant failure.
Thus, the difference is clear. It is good to fail, as long as it helps you to keep moving. If despite multiple failures, you are rooted at the same spot, it is perhaps time to take a hint, that whatever is happening is not suiting you. Either you need a change or you need a break. You definitely can’t keep going.
How to check if the failure you are going through is helpful or unhelpful? After all, life is not as simple as race practice for child A and B. Here are some pointers to help you decide:
Do you feel like you learned something? Or has there been no increase in learning?
How do you feel emotionally? Is it the tough frustration of doing a difficult task or is it the empty frustration of waste of time?
Can you gauge your progress since the time you started? Have you made any movement at all? If you are too biased to judge this, get an external opinion. Get a friend who can be honest with you, to tell you if you have made any progress or not.
Did you take a break any time? Sometimes, what seems like redundant failure can be turned into helpful failure if you can take a break and be away from the task for a little while. There are a lot of unconscious processes involved in learning which kick in when you do something entirely unrelated, but are going on in the back of your mind.
Did you get help? Sometimes, learning a new skill can need external help as it may require more resources than what you have. Getting that help can help you make redundant failure into helpful failure.
After all these, if you still feel stuck, you should leave the task because it may not be meant for you. Right now, it will just cause you endless frustration. If you want, you can come back later and try your hand at it again.