I have programmer friends in their 40s to 60s who are seriously depressed currently (and 20 year olds worried for theirnl future perspectives, of course). Mental health is not just a young person's game.
I strangely feel quite lucky that I got more and more into electronics and hardware over time as I moved from web and desktop more and more into embedded/consumer electronics and companies who also employ mechanical and EE engineers. When I was younger I used to dumbly worry this meant giving something up (the purity of software approaches, etc.), but instead it made me consider myself an Engineer with a capital E and strive to learn the engineering method more generally, and learn so many other fields of the trade. It turns out this is a much more resilient identity than just Programmer and I recommend that approach.
However, it's pretty nice that these days I can also swing a semi-decent PCB, know my way around scopes and logic analyzers quite well, CAD something up for DFM in a number of processes from thermoplastics to machining, taught myself a fair bit of structural engineering, set up a FEM analysis correctly, etc. If only because it lets me bridge worlds and tie software and hardware together more effectively in the projects I'm in.
I cannot do any of these things as well as a seasoned veteran, but it has given me a broader appreciation of engineering overall and the commonalities between it all, to the point where I can also muster up leadership in engineering orgs more broadly and am not as hurt over the prospect that my pure programming skills might get devalued or diluted, or change.
For example, software engineers generally scoff at the perceived crustyness and lack of agility in classical mechanical engineering processes, but on the other hand mechanical engineering is far more experienced at defense-in-depth type approaches, dealing in components that have a failure rate to them and designing with error bars and safety factors, and I find some of that mindset has transferred quite naturally to engineering with our unreliable LLM friends at scale the past two years.
It takes a lot of the sting out if listening to Phish isn't your only move. Well, maybe not a lot, but at least it doesn't get so existential. Don't be a Programmer, be an Engineer. It's a lot easier to feel useful during a time of much doubt.