I'm not talking about switching professions at some point in your life. More specifically, doing your career over again in the same profession, in order to redeem your past failing career.
Either you got "too comfy" in your job, didn't learn much, then found a very tough time being a good fit for other jobs. Or you simply have stopped being a good hire for other reasons. What did you do to redeem yourself in the eyes of your respective industry?
I was a great C++/OO dev for 10 years before I got bored, starting doing management, business focussed roles and more high level devops style work. After 10 years of that I wanted to move back into pure coding. With great experience should be easy right? Wrong.
I got a mid-level java/python dev job and it was difficult, I was out of touch and everything was different or new. Languages, styles, CI/CD, DI, git, containers, unit testing its a huge amount to learn. After a year I got laid off because I was getting paid like a senior but not keeping up with the grads.
A few years later I'm productive and useful in this new world but I dont really like it. I'm enjoying Scala and functional programming but with so many libraries and tools I feel like everything is so difficult and complicated. It takes a lot of study effort to keep up. Also I'm never sure if its because the applications I work on are badly designed, or I just dont really understand modern design. I have a business specialty which keeps me employable but I miss the old days when things were simpler.
Being "old" at 40+ really isn't so easy - I'm not sure you can ever redeem yourself in the eyes of the industry. Best you can hope for is get a non-tech domain specialty and find a big stable company that values experience and try to keep working on interesting projects. Once you're laid off or fired once its really hard to be the super confident hacker you were at 25.
EDIT - thinking about if you want advice. Get a business specialty or technical niche. Dont get too lazy, if you aren't learning on the job for a few years in a row, change the tech in the project or leave. It should be easy to keep employed but you have to keep working at it. Best career money-wise is to move to management, but its difficult to move back. Dont take the high paying job on a dead end project without a plan to get out.