Fix error handling in _generator

Closes #137