Qix-/better-exceptions

List of small errors to fix and possible improvements to implement

Open

#47 opened on Sep 13, 2017

View on GitHub
 (12 comments) (2 reactions) (0 assignees)Python (4,489 stars) (210 forks)batch import
bugenhancementhelp wanted

Description

I prefer to gather everything here rather than opening a ticket for each of them, as some bugs are really minimal. Some points are just ideas I have had.

  • Nested issues are not displayed (see)
  • Surround repr(value) with try / except just in case something goes wrong (see traceback source code)
  • Print Traceback (most recent call last): right before formatting the issue, so user have a clue about what is going wrong if formatting hangs (see #37)
  • \n inside a string should be escaped, no newline should be displayed (see)
  • SyntaxError are wrongly truncated (see and see #35)
  • Multilines expressions like a = 1 + [2, \n 3] are not enhanced
  • Encoding issues:
    • "天" / 1 is wrongly displayed as "天" / 11 because of utf-8 string slicing (see)
    • Do not force char decoding, stay close to the default behavior displaying "\u5929" instead of "天" if LANG = en_US.ascii (see)
    • Keep the quotation marks and u string prefixes used in the source code, do not replace them with ' marks (see)
    • Encoding long strings may raise an error (see #34)
  • Possible readability improvement:
    • Syntax highlighting could (optionally) include operators (*, +, -, /, ...), functions, methods
    • int and string values could be highlighted with two different colors
    • Traceback frames could be optionally spaced between each others (see)
    • Is it possible for shadowed built-in (len = lambda x: 5) to not be higlighted as a built-in?
    • Location (File "test.py", line 13 in func) could be colored (see #38)
    • Other messages (like Exception: XXX, Traceback (most recent call last):, ...) could be optionally colored too
    • Traceback relevant to the user could be bold / not relevant could be dimmed (see #38)
    • Advanced user could have more control over formatting to suit its need with colors which works best on its terminal, or by customizing style (see #39). For example: import better_exceptions; better_exceptions.THEME['location_message'] = 'File "{filepath} +{lineno}", in {source}'. Maybe use ansimarkup to easily colorize / strip (if SUPPORTS_COLORS is False) messages.
    • c = self.a + self.b: is it possible to give information about a and b? It seems very complicated. What about dct['key'], lst[3], obj.val, a.b.c, x.get('key', default), etc.

Contributor guide