Improved error checking when listing branches