Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Debugging ? #49

Open
ed2050 opened this issue Dec 22, 2020 · 5 comments
Open

Debugging ? #49

ed2050 opened this issue Dec 22, 2020 · 5 comments

Comments

@ed2050
Copy link

ed2050 commented Dec 22, 2020

Hey guys, great project! I'm impressed by how clean and syntax-complete this is. Several other python-to-js solutions are a pain to use or break python syntax in unexpected ways.

Question (since I don't see a discussion board or mailing list):

How can I debug pscript programs? Running the compiled js gives error messages in the console that don't relate to my python code at all. Is there some magic trick to get python line numbers in error messages? Any other suggestions for how to debug? Running in cpython only goes so far, the browser / DOM data don't exist there.

Thanks, best wishes.

@nathanielatom
Copy link

It's been awhile since I've used it, but I think you can use the JavaScript debugger command, just add it to a new line in your pscript similar to how breakpoint() would be called in python. Then if you open the browser developer tools console and reload / execute the relevant code it should trigger the debugger and allow you to step through the transpiled JS and see the values of variables. There's also good old-fashioned print() debugging, which logs to the browser console; gl :)

@ed2050
Copy link
Author

ed2050 commented Dec 24, 2020

Thanks, I'll give it a try. Been using print debugging (or in this case, log debugging) for too long. :)

Anyone know how to generate source maps with pscript? Some transpilers generate source maps so that errors indicate the line in the original python code instead of a line in the javascript code. Would be very handy if pscript supports that. Thanks.

@almarklein
Copy link
Member

Yeah, at the moment you'll have to debug the JavaScript that has been generated and then figure out how to update your Python code. This can be a painful task, I know.

Source maps would be great, but PScript does not produce these. They would not fully solve the problem, because there's still several JS gotcha's to take into account, but at least it would make it easier what Python code is failing.

@ed2050
Copy link
Author

ed2050 commented Dec 28, 2020

No worries Almar. It's going quite well, actually. Very nice that pscript preserves the python method names. Easy to see the call chain where things went wrong. Having short methods helps too. :)

By contrast, brython reproduces python runtime errors almost exactly - yet can still be very difficult to debug. Because the parser emits pages and pages of unintelligible javascript class errors on bad syntax. It can be a real pain finding that one misplaced ] in a long file. More than once I've had to resort to binary search debugging: comment out half the code, see if the error occurs, comment out half the remaining code, repeat ad nauseum. :)

@almarklein
Copy link
Member

This is our punishment for trying to run Python instead of JavaScript in a browser :)

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

No branches or pull requests

3 participants