I've found that as I've gained more experience, I learn from my previous mistakes, and over time it slowly improves so that I'm making fewer mistakes and debugging the mistakes I do make more quickly. I remember that when I started learning software development, there were a lot of roadblocks to progress that were caused by my lack of experience. Such roadblocks have mostly disappeared for me.
My code still has bugs, of course, but I can usually identify and squash them a lot more easily now. I still encounter the occasional frustrating issue, but it's a lot better overall.
My mistake rate spikes when I'm learning a new technology or language of course, but that subsides once I get used to it.
Attention to detail helps a great deal, but I know that this can sometimes get tiring.
Of course it also helps to work with compiled languages rather than interpreted languages. :) More of those mistakes get caught by the compiler.
For interpreted languages, I find that linters are good for finding issues and some IDEs have integrated linting and possible mistakes are highlighted right there in the editor. I like the WebStorm IDE for Javascript development (node.js or client side) and it wouldn't surprise me if SublimeText had something to help spot code issues.
So if you stick with it, it'll likely get better and less frustrating. In the near term, my suggestion is to use tools that assist you in avoiding simple mistakes like typos.
Another suggestion would be to walk away from something that is causing you frustration and come back later. I sometimes find that a particularly infuriating problem is more easily solved if I take a break from it for a while.