replit / prybar

Pry open those interpreters.
GNU General Public License v2.0
253 stars 52 forks source link

[nodejs] don't run code twice on error #88

Closed wbourne0 closed 2 years ago

wbourne0 commented 2 years ago

https://app.asana.com/0/0/1202058950801330

To avoid confusing errors in stack traces, we would re-run compiled code if it error-ed to avoid syntax errors on lines that don't exist.

This caused the following code to run twice since "compile" in nodejs is "compile and run."

console.log('hi');
throw new Error('blah');

Since the only errors we care about are syntax errors, we'll instead use compileFunction from vm to validate the syntax - if it fails, we'll compile the original code (to get an appropriate error); otherwise we'll compile the code with our footer (at this point we don't care if the code fails since the callsites will be on the correct lines).

replbot commented 2 years ago

unbooping: approved

wbourne0 commented 2 years ago

woah, nice job! is there any test that can be added to ensure that we don't accidentally regress?

Not easily atm, currently the only tests for prybar are i/o tests.