AssemblyScript / assemblyscript

A TypeScript-like language for WebAssembly.
https://www.assemblyscript.org
Apache License 2.0
16.82k stars 655 forks source link

process.exit in compiler frontend API limits usage #2112

Open jimpo opened 2 years ago

jimpo commented 2 years ago

The docs say that the compiler can be called programatically using the cli/asc.js API. But there are situations where it may crash and instead of throwing an Error which could be caught, this module calls process.exit. This limits the contexts that could embed directs calls to this API. I think either there should be an API option not to call exit on crash, or the docs should state that the API should only be called in a subprocess.

MaxGraey commented 2 years ago

process.exit called only when we have very abnormal situation and can't recover compiler. If you want to do something before exit you could add hook like process.on('exit', () => { ...some custom cleanups or/and save.... });

trusktr commented 2 years ago

It seems very reasonable to be able to try-catch errors, especially if the error handling is part of a bigger applications (for example, imagine a repl or IDE that passes code through compiler: instead of exiting, it needs to display issues.