Make end() work on errors in beforeMain