Skip to content

The python code reports an error and cannot locate the specific location #503

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

Open
y1y2 opened this issue May 14, 2025 · 1 comment
Open

Comments

@y1y2
Copy link

y1y2 commented May 14, 2025

python code reports an error, but it cannot locate the specific line and can only reach the specific function. However, javascript can

def multiSite(ctx):
    tc = base.traceContext()
    req = base.parseJsonString(ctx.getBodyAsString())
    base.logInfo(tc, f"ceshi,{ req['AAA']}")
Image
@msimacek
Copy link
Contributor

Hi. It's a known issue that the Java stacktraces don't show the location well, unfortunately it's very hard to fix. You can catch the exception and use the python exception printer to get a python traceback. Like this:

try {
    context.eval("python", ... your code);
} catch (PolyglotException e) {
    Value formatException = context.eval("python", """
            def _format_exception(e):
                import traceback
                return ''.join(traceback.format_exception(e))
            _format_exception
            """);
    System.out.print(formatException.execute(e.getGuestObject()).asString());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants