Fix Error handling for generator