How to repair and/or reinstall Homebrew safely?
This happened to me because I had two tabs open in my console. In Console A I removed the current working directory of Console B. Then, without thinking about it, I ran brew upgrade in Console B. Of course it threw the above error.

Simple solution: just cd to a different directory in Console B and brew upgrade again.

Me and my infinite wisdom.