New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle error in async callback #53
Comments
You can handle asynchronous errors like this: process.on('uncaughtException', (err) => {
console.log(err);
}) Keep in mind that this catches all exceptions from both inside and outside of the VM. |
Thx. Yes, it partially helped me. BTW, is there any way to distinguish if error in 'uncaughtException' is related to a VM (and possibly, which of them) or not? |
Unfortunately not at the moment. I have an idea how to implement this but it will take some time. |
I'm wrapping vm.run() with domain.run() and it seems to work. I don't know if it has any side effects though..
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@alsterg The method seems to lose effectiveness.. @patriksimek Could you please tell me if you forgot about this? |
Confirming @ImSingee, method unfortunately does not work anymore. |
Any updates on this??? |
This is pretty messy so I'm not recommending anyone do this, but I'm posting the way I got around this here. I wanted my scripts to be able to contain To catch errors inside the async IIFE, I used another IIFE inside a try/catch to store the result, then returned a status key to tell me if there was an error or not. (async () => {
try {
let result = (() => {
// script here
})();
return { status: "success", result: result };
} catch (e) {
return { status: "error", error: e.message };
}
})(); |
Is there any way to handle error in async callback?
I'm seeking for a way to prevent whole script crashing.
The text was updated successfully, but these errors were encountered: