Live data from Hacker News

Show HN: Debugging-Friendly Tracebacks for Python

github.com

1–10 of 13 posts

Re: Show HN: Debugging-Friendly Tracebacks for Python

#2
pytest also has helpful tracebacks; though only for test runs.

With nose-progressive, you can specify --progressive-editor or update the .noserc so that traceback filepaths are prefixed with your preferred editor command.

vim-unstack parses paths from stack traces / tracebacks (for a number of languages including Python) and opens each in a split at that line number. https://github.com/mattboehm/vim-unstack

Here's the Python regex from my hackish pytb2paths.sh script:

  '\s+File "(?P.*)", line (?P\d+), in (?P.*)$'
https://github.com/westurner/dotfiles/blob/develop/scripts/p...

Re: Show HN: Debugging-Friendly Tracebacks for Python

#5

It would be nice to integrate the context functionality into https://github.com/Qix-/better-exceptions

I always liked how this automatically hooks into the python installation via pip, but preferred another text format. Hm. So if you want to permanently replace python's crash message, you could put a file `sitecustomize.py` into your python path, with these contents for example:

    # in site-packages/sitecustomize.py:
    print('hello!')
    import sys; sys.excepthook = lambda a,b,c: print('')
    # or also:
    import stackprinter
    stackprinter.set_excepthook(style='darkbg')
(you can find the path by `python -c "import site; print(site.PREFIXES)" `)

It felt bit much to do that automatically on installation, but maybe it would be a good option to have

Re: Show HN: Debugging-Friendly Tracebacks for Python

#7
post #5

It would be nice to integrate the context functionality into https://github.com/Qix-/better-exceptions

I always liked how this automatically hooks into the python installation via pip, but preferred another text format. Hm. So if you want to permanently replace python's crash message, you could put a file `sitecustomize.py` into your python path, with these contents for example: # in site-packages/sitecustomize.py: print('hello!') import sys; sys.excepthook = lambda a,b,c: print(' ') # or also: import stackprinter sta…

In case you're looking for opinions there: I pretty much like libraries like this for development but prefer manual activation, e.g. only when my system is running with a debug flag, over libraries messing with the environment itself.

Thanks for making it available, the output looks neat, looking forward to try it out.

Re: Show HN: Debugging-Friendly Tracebacks for Python

#8
If you're building a server application, you should be aware of the kinds of information you're writing to your application log. The first obvious issue is that of possibly disclosing information if the traceback is returned to the client instead of saved in the server log. The second, less obvious question is what kinds of statutory requirements you are under regarding retention of PII in your logs. And in the worst case scenario, you could end up writing out things like plaintext passwords and unrelated PII from the environment.

I bring this up because this looks like it discloses variable values into the log that would not be printed in a standard traceback under most normal circumstances.

Re: Show HN: Debugging-Friendly Tracebacks for Python

#9
post #8

If you're building a server application, you should be aware of the kinds of information you're writing to your application log. The first obvious issue is that of possibly disclosing information if the traceback is returned to the client instead of saved in the server log. The second, less obvious question is what kinds of statutory requirements you are under regarding retention of PII in your logs. And in the worst…

+1 to this. We have some middleware that scrubs our database exceptions for precisely this reason. You need to think about this any time you're logging the value of any variable, if your company handles any PII or other sensitive information whatsoever.
Post reply on HN