Make end() work on errors in beforeMain

If an error happens in beforeMain, stats.main isn't initialized.