chaquo/chaquopy

Convert Java stack traces into Python format

Opened this issue · 0 comments

The reverse (converting Python exceptions to Java format) is already implemented, and marks Python frames with a package name of <python>. But if you use the Python console to trigger a Java exception, you get a confusing mixture of Java and Python stack traces:

>>> Integer.parseInt("abc")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "class.pxi", line 962, in java.chaquopy.JavaMultipleMethod.__get__.lambda3
  File "class.pxi", line 1000, in java.chaquopy.JavaMultipleMethod.__call__
  File "class.pxi", line 781, in java.chaquopy.JavaMethod.__call__
  File "class.pxi", line 936, in java.chaquopy.JavaMethod.call_static_method
  File "env.pxi", line 292, in java.chaquopy.CQPEnv.CallStaticIntMethodA
  File "env.pxi", line 546, in java.chaquopy.CQPEnv.check_exception
java.lang.NumberFormatException: Invalid int: "abc"
	at java.lang.Integer.invalidInt(Integer.java:138)
	at java.lang.Integer.parse(Integer.java:410)
	at java.lang.Integer.parseInt(Integer.java:367)
	at java.lang.Integer.parseInt(Integer.java:334)
	at com.chaquo.python.PyObject.callAttrThrows(Native Method)
	at com.chaquo.python.PyObject.callAttr(PyObject.java:209)
	at com.chaquo.python.utils.ReplActivity$Task.run(ReplActivity.java:36)
	at com.chaquo.python.utils.ConsoleActivity$Task.lambda$start$0$ConsoleActivity$Task(ConsoleActivity.java:350)
	at com.chaquo.python.utils.-$$Lambda$ConsoleActivity$Task$AONo-zGHGFofNeDXqOaxrxZtbco.run(lambda)
	at java.lang.Thread.run(Thread.java:818)

There was previously no public API for manipulating Python stack traces, but one was added in Python 3.7 (types.TracebackType).

Any Java frames not located between the throw and the catch (e.g. callAttrThrows and below in the trace above) should be omitted from the trace when caught by Python.

Update the documentation to match.