You are being very hard on yourself. If a friend shared this experience with you, you probably would not warn them that they are at risk of becoming a “40-year-old loser.” My guess is that you would provide encouragement and reassurance.
Things did not evolve as planned but you have had a successful career. An unexpected event occurred that was outside of your control. How could you have predicted such an outcome? The answer is that there is no way you could have known. You cannot change history but you can learn from it.
My advice is to reframe your view of this situation. You are not a failure. You were highly successful for a significant period of time but due to events outside of your control, you’ve lost your income. You are comparing yourself to your friends but each person has unique life circumstances. It is not a fair comparison.
You are only seeing the negative aspects of your situation but there are positives. Now you have a chance to do what you always wanted. Many people never have this opportunity. They live their entire lives engaged in a less-than-ideal career and never change course. You have that opportunity now. In this way you are very fortunate. Had the unforeseen event not occurred it may have been impossible to begin a new career. Think of it as a gift. You are now in the position where you must forge on and start over. Maybe this is the jumpstart that you’ve needed to change the course of your life to a new, more desirable direction.
You are now on the verge of doing something that you have always wanted to do. Going forward will be an uphill battle but you have no choice. It won’t be easy but nothing that is valuable in life ever is.
I wish you the best of luck with your future endeavors. If you have continued difficulties, it would be advantageous to consider therapy. A therapist can help you remain objective and also support your efforts to rebuild your career. There is no shame in wanting to ensure that one’s thought processes are as sharp and as realistic as possible. In addition, it will allow you to receive the mental health treatment you regret not pursuing 15 years ago. Please take care.