emit errors instead of calling process.exit()

Improvement to #520 error handling