beeware / batavia

A JavaScript implementation of the Python virtual machine.
http://pybee.org/batavia
Other
1.39k stars 424 forks source link

Different traceback format in runAsPython and runAsJavaScript #468

Open abonie opened 7 years ago

abonie commented 7 years ago

In case of uncaught exception runAsPython's traceback contains line which caused said exception, while runAsJavaScript does not. As a result some test cases that should raise an exception fail showing diff like this:

  Traceback (most recent call last):
    File "test.py", line 2, in <module>
+     print(next(i))
  StopIteration
      test.py:2
 : Global context

(this particular traceback comes from this test case https://github.com/abonie/batavia/blob/master/tests/builtins/test_next.py#L29 on my fork, once you remove @expectedFailure)

I believe this is not expected behaviour. I am not sure though which version should be correct. If this code was run line-by-line by CPython interpreter, there would be no additional line, however afaik runAsPython puts code to be executed in a file test.py and runs it with python test.py which results in slightly different traceback (i.e. said extra information showing line that caused exception)

bhardwajaditya113 commented 7 years ago

Hi mentors, I am a newbie, would like to contribute to this project. Kindly help me with the first PR. Thanks.

abonie commented 7 years ago

Hi @bhardwajaditya113, this topic is meant for discussing this one particular issue only. I suggest reading this: http://pybee.org/contributing/how/first-time/what/batavia/ and posting any further questions here: https://gitter.im/pybee/general.

abonie commented 7 years ago

Possibly related to this issue, if second exception is raised while handling previous exception, e.g.:

try:
    raise Exception('1')
except Exception as err:
    raise Exception('2')

Batavia will lose / suppress information about the first exception (same behaviour occurs if second exception is thrown this way: raise Exception('2') from err)