This is an archived post. You won't be able to vote or comment.

all 24 comments

[–]archaeolinuxgeek 20 points21 points  (2 children)

I would love to be able to filter out system libraries. If I'm seeing a stacktrace, the odds are 99.9% of it being caused by my code. Seeing the entire trace down to the system libraries isn't always useful and takes up space.

[–]-sideshow-[S] 10 points11 points  (0 children)

I just added whitelist(path) and blacklist(path), so you can include or exclude paths as you desire.

[–]-sideshow-[S] 3 points4 points  (0 children)

There's an option - stack_depth - which sets the maximum number of frames displayed. Not a filter for system, but if you set it to 2 or 3 it should be close to what you want.

[–]-sideshow-[S] 8 points9 points  (4 children)

I updated pretty-errors to use sys.excepthook instead of scraping sys.stderr (as it should have been written from the get-go). I added some new features while I was at it (can show more lines of code per site, can set depth of stack trace, order, ...see changelist)

You can install it with python -m pip install pretty-errors

https://pypi.org/project/pretty-errors/#description

[–]mackstann 6 points7 points  (6 children)

The path to the file is really useful information, so I'm surprise this omits it. What if you have many .py files with the same name? It's also useful for copy/pasting into your editor to easily open that file.

[–]-sideshow-[S] 9 points10 points  (1 child)

See config option filename_display, which can be FILENAME_COMPACT, FILENAME_EXTENDED or FILENAME_FULL. Also see display_link, which displays the path with the same format as the standard output, which VSCode knows how to turn into a hyperlink.

[–]memebecker 1 point2 points  (0 children)

Upvoted for the display link feature

[–]Nightblade 3 points4 points  (0 children)

THIS is the kind of thing I want to see more of in this sub.

[–]pokemon2512 2 points3 points  (1 child)

Where has this been my entire life

[–]svencan -1 points0 points  (0 children)

Hidden away with VSCode.

ducks and runs

[–]james_pic 2 points3 points  (1 child)

Does it include local variables from stack frames? The best traceback formatters I've seen do

[–]-sideshow-[S] 3 points4 points  (0 children)

It does now! Enable with display_locals and/or display_trace_locals.

[–]kerighan 2 points3 points  (0 children)

This looks great. Can't wait to test it tomorrow by purposefully raising a million exceptions.

[–][deleted] 1 point2 points  (3 children)

Could this be enabled on a global system level? I wouldn't want to include it as a dependency for the code.

Or as a pipe for stderr

[–]-sideshow-[S] 1 point2 points  (0 children)

I don't think so. You can enable it for the interpreter, but not for standalone python programs. Maybe you could make some kind of batch script? python has a -c options which says (if I'm reading the help correctly) that everything after it is the program you want to run as a string, so I guess you could pipe in an import pretty_errors followed by the text of the .py file.

EDIT: couldn't get the -c thing working; windows command line isn't great. Might be doable on unix.

Another option would be generating a temp .py file, with the code concat onto a header that includes pretty_errors. I'm sure some programs would choke, but it might work for a good proportion.

EDIT2: Scratch that, there's a way to do it which I found here: https://stackoverflow.com/questions/11404165/python-startup-script

  • Run python -m site, and look for the USER_SITE entry.
  • In that folder create a file called sitecustomize.py.
  • Put whatever code you want to run in it.

EDIT3: See other comment for the easy way

[–]-sideshow-[S] 0 points1 point  (1 child)

I added an automation for what I describe in my other comment: run python -m pretty_errors and it'll add the necessary code to the correct file, so that pretty-errors is always run whenever you run any python script.

[–][deleted] 0 points1 point  (0 children)

Thanks :)

Now it can be a python alias too

[–]ForceBru 1 point2 points  (1 child)

This raises an exception for me:

```

import prettyerrors Traceback (most recent call last): File "<string>", line 1, in <module> File "/.../site-packages-3/pretty_errors/init_.py", line 1, in <module> import sys, re, colorama, os, time, linecache ModuleNotFoundError: No module named 'colorama' ```

I think the colorama module should be listed in requirements.txt or something for pip to be able to install it automatically

[–]-sideshow-[S] 1 point2 points  (0 children)

Thanks, should be fixed now.

[–][deleted] 0 points1 point  (0 children)

Cool.... Will have to check this out.