Adds emitting of end event on error.