Improve error handling when wrong branch is pushed

Basically, improved error handling. The scenario was causing a null ref exception which was being lost.

Fixes #1051