pythonpygmentstrepan

KeyError: 'darkblue' when using trepan3k


I installed trepan3k with pip3 install trepan3k and I want to debug a file with trepan3k main.py, but I'm getting this error:

Traceback (most recent call last):
  File "/usr/local/bin/trepan3k", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/trepan/cli.py", line 212, in main
    normal_termination = dbg.run_script(mainpyfile)
  File "/usr/local/lib/python3.7/site-packages/trepan/debugger.py", line 217, in run_script
    exec(compiled, globals_, locals_)
...
  File "/usr/local/lib/python3.7/site-packages/pygments/formatters/terminal.py", line 101, in format
    return Formatter.format(self, tokensource, outfile)
  File "/usr/local/lib/python3.7/site-packages/pygments/formatter.py", line 95, in format
    return self.format_unencoded(tokensource, outfile)
  File "/usr/local/lib/python3.7/site-packages/pygments/formatters/terminal.py", line 126, in format_unencoded
    outfile.write(ansiformat(color, line.rstrip('\n')))
  File "/usr/local/lib/python3.7/site-packages/pygments/console.py", line 68, in ansiformat
    result.append(codes[attr])
KeyError: 'darkblue'
Uncaught exception. Entering post-mortem debugger...
trepan3k: That's all, folks...

This happens on macOS Mojave as well as Ubuntu 18.04. What is going on and what can I do to debug with trepan?


Solution

  • Upgrade trepan3k to version 0.8.9 that I just released and I think you will be fine.

    Longer story. I am sorry I didn't see this earlier. As a big user of trepan3k myself, I had noticed this a while ago and had been working around it by using previously installed versions of trepan3k. Since I wasn't aware of anyone else noticing this, I didn't think to investigate, let alone fix it.

    Then at some point I had some free time, and did investigate. The longer answer is that there seems to have been an update to Pygments after 2.2.0 that is incompatible and color names are different.

    I wish I understood in more detail what's going on in Pygments. I suspect it has to do with using a reduced set of color names and handling dark and light backgrounds in a way that doesn't mess things up when you switch between dark and light.

    If there is someone out there that knows and would elucidate I'd be grateful. And bonus points if you know exactly how change Pygments to a version after 2.2.0.

    The relevant code that trepan uses for working with Pygments is https://github.com/rocky/python3-trepan/blob/master/trepan/lib/format.py

    I had to write a custom formatter for RsT to console. I had offered this to the Pygments community, but they decided that this shouldn't be in Pygments, but it was fine to have it in trepan3k the way it is.

    This is one small example of the extra work you find in this debugger that aren't in the others in order to support a better user experience. Deparsing to show exact location is another example. But that means of course there's more possibility of breakage when packages do an incompatible upgrade.

    So the final two takeaways.

    1. If there's a bug in trepan3k, please report it in its issue tracker: https://github.com/rocky/python3-trepan/issues/new. I am more likely to see this there than as a Stack Overflow question.
    2. If you haven't already, upvote the project. I use Github ratings to help guide me to know what work on when I have free time.