pygments / pygments/pygments

Unhandled Exception in Windows while using less.exe

Open
#1,420 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.2k
Forks
885
PR merge metrics
No merged PRs in 30d

Description

Hello pygment folks,

Just started to use pygmentize on windows as I'm looking to get less.exe to have syntax highlighting. Works great. However, if I pipe the results to less and then hit 'q' to exit less, I get the following issue.

pygmentize -v fin.scm | less

(the code is displayed colorized...I then hit q to exit)

*****************************************************************
An unhandled exception occurred while highlighting.
Please report the whole traceback to the issue tracker at
<https://github.com/pygments/pygments/issues>.
*****************************************************************

Traceback (most recent call last):
  File "c:\apps\python\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\apps\python\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Apps\Python\Scripts\pygmentize.exe\__main__.py", line 7, in <module>
  File "c:\apps\python\lib\site-packages\pygments\cmdline.py", line 550, in main
    return main_inner(popts, args, usage)
  File "c:\apps\python\lib\site-packages\pygments\cmdline.py", line 518, in main_inner
    highlight(code, lexer, fmter, outfile)
  File "c:\apps\python\lib\site-packages\pygments\__init__.py", line 84, in highlight
    return format(lex(code, lexer), formatter, outfile)
  File "c:\apps\python\lib\site-packages\pygments\__init__.py", line 66, in format
    formatter.format(tokens, outfile)
  File "c:\apps\python\lib\site-packages\pygments\formatters\terminal.py", line 95, in format
    return Formatter.format(self, tokensource, outfile)
  File "c:\apps\python\lib\site-packages\pygments\formatter.py", line 95, in format
    return self.format_unencoded(tokensource, outfile)
  File "c:\apps\python\lib\site-packages\pygments\formatters\terminal.py", line 120, in format_unencoded
    outfile.write(ansiformat(color, line.rstrip('\n')))
BrokenPipeError: [Errno 32] Broken pipe

This looks a bit different than #1109 and #1153 although it may be the same root issue.

Certainly not a critical issue as it's just an error message at the end, but I wanted to ensure it was reported and I do hope it's a simple fix.

Thanks for the time to look at this and the great program.

Michael

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with pygments/formatters/terminal.py, especially format_unencoded, and reproduce the reported pygmentize -v fin.scm | less command on Windows before pressing q. Compare the BrokenPipeError with related issues #1109 and #1153; done means exiting less no longer produces an unhandled exception or traceback.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.