A lot of times, when I update brew, I need to make a prayer before updating. Now when I every time I update, I do the following. And I haven't had a problem since.
Resetting brew formulas to be identical to their repositories.
Then, as usual, update, upgrade, and cleanup.
In case of a problem, I run
brew doctor, but I haven't had to do it since running update-reset.