Fix throwing errors into the generator

Fixes issue #5 and adds the test case from #5 to test.js.