Add a link to the line with print

While debugging I often sprinkle the code with print statements, then I examine the printed output, then I spend time figuring out where that print came from.

I don’t like to spend that time, so I would like to be able to get to the row that executed that print with one click.

Possible implementations could be:

print('xxx')                  # always put the link on the output
print_link('xxx')             # use a dedicated print function
print('xxx', with_link=True)  # use an optional argument

Possible outputs could be:

  • The printed text has a link to the line similar to the one in the diff
  • The printed text is clickable. When you click on it, the editor opens and the line with print is selected
  • The printed text is clickable. When you click on it, a popup with the traceback at the time of the print is shown and clicking on any line of the traceback, opens the editor at that line

The last option would be the most useful, because it allows to see what called any generic function that prints to the app log.

If adding the traceback info to every printed line would bloat the app logs, this could be an optional app setting that allows to enable it always/only in debug/only explicitly (with with_link=True or with with_traceback=True).

EDIT
This would also answer this question: How do I show the content of the call stack on the client?

8 Likes

Or a function other than print?

A dedicated print_whatever that included a stack trace would be terrific. There are times when I want a simple debug output, and there are times when I really want to see the stack trace. Right now to see the stack trace I have to raise an exception, which stops execution at that point.

3 Likes

Yeah, I create enough Exceptions accidentally as it is – I can’t stomach adding them intentionally!

3 Likes