Any way to capture errors from vm.runInNewContext?

527 views
Skip to first unread message

Jeremy Darling

unread,
Dec 10, 2014, 7:01:47 PM12/10/14
to nodejs
Is there any way to actually capture exceptions from code running vm.runInNewContext or vm.runInContext, etc...?  Seems there should be an on('error') or something callback but can't find it.

Wrapping the call in try/catch does't capture anything that is within an async call within the script being executed.

 - Jeremy

Andrey

unread,
Dec 10, 2014, 10:49:06 PM12/10/14
to nod...@googlegroups.com
no. You are only creating context, not full sandboxed JS environment.
The code is called from the same event loop and functions you have in your context are same regular functions as in the rest of the code.
All possible solutions are same as for "how do I handle async errors" question. Use domains, zones, co+generators etc (nothing gives you 100% guarantee)

Jeremy Darling

unread,
Dec 10, 2014, 11:34:50 PM12/10/14
to nodejs
Hadn't thought of wrapping the code in a domain, thanks for the idea.  Will give that a try and see if it gets me closer.  Trying to catch typos on a remote SSH client instead of just getting a generic Hapi error back.

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/c8fb51bd-e38a-4dd3-8257-8b91b34fefec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages