You take the courses. You learn to watch out for biases. You attempt to account for all variables. But you can't control for the biases you don't even know you have. And if your work is attacked, scientist or not, its human nature to circle the wagons. This, in my opinion, is what happened with the climate scientists--a lot of them anyway--with the hockey stick and "ClimateGate."
It all got a bit too cozy for them, peer-review standards were a little lax and--wham!--they get hit out of left field by a retired engineer with too much time on his hands showing relatively abstruse, and not particularly significant, errors in their various analyses.
The correct thing to do in that case--the scientific thing to do--is to thank the person for providing the correction and reworking the data. But that's not what happened. Instead they got pissy because they'd been shown to be wrong. They holed up, hid their data, adopted a siege mentality. It wasn't wholly unwarranted, because they were getting thousands of requests monthly, and there's no doubt a lot of the requests were intended to be frivolous and vexatious. Still, the damage this cabal of climate scientists did was incalculable. Climate change was out on its ear, despite having an excellent theoretical and experimental basis.
They'd simply lost the rhetorical war. Humans are essentially beings of passion, not reason, something the forces aligned against global warming knew form the start. It was the application of the Inverse Tinkerbell Theory: If enough people don't believe in it, it won't be true.
The truth will out eventually, since indications are that we will continue to increase the rate at which we oxidize organic carbon. By 2050 we should have a pretty good idea.