glutanimate / syntax-highlighting

A fork of Tiago Barroso's Syntax Highlighting add-on with support for Anki 2.1
https://ankiweb.net/shared/info/1463041493
Other
108 stars 27 forks source link

Error while using "PostgreSQL Console" #12

Open 100cube opened 4 years ago

100cube commented 4 years ago

Trying to highlight PostgreSQL Console raises exception

Hi, First, thanks for your great add-on. I was trying to highlight some SQL and psql ( the command line interface for PostgreSQL).

Steps to reproduce

  1. Enter the following text in the Add window. \dt
  2. Select PostgresSQL console (psql) from the language dropdown, highlight the text entered and try either pressing alt-S or clicking on the highlight button (LIGHTENING).

I ended up getting the following error

Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed. 
If the issue only occurs when add-ons are enabled, please use the Tools>Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem. 
When you've discovered the add-on that is causing the problem, please report the issue on the add-ons section of our support site. 
Debug info:
Anki 2.1.15 (442df9d6) Python 3.7.4 Qt 5.12.5 PyQt 5.13.1
Platform: Linux
Flags: frz=False ao=True sv=1
Add-ons possibly involved: Syntax Highlighting for Code

Caught exception:
  File "/usr/share/anki/aqt/editor.py", line 138, in <lambda>
    activated = lambda s=self: func(s))
  File "/home/<USERNAME>/.local/share/Anki2/addons21/1463041493/main.py", line 412, in highlight_code
    highlight(code, my_lexer, my_formatter),
  File "/home/<USERNAME>/.local/share/Anki2/addons21/1463041493/libs/pygments/__init__.py", line 85, in highlight
    return format(lex(code, lexer), formatter, outfile)
  File "/home/<USERNAME>/.local/share/Anki2/addons21/1463041493/libs/pygments/__init__.py", line 64, in format
    formatter.format(tokens, realoutfile)
  File "/home/<USERNAME>/.local/share/Anki2/addons21/1463041493/libs/pygments/formatter.py", line 95, in format
    return self.format_unencoded(tokensource, outfile)
  File "/home/<USERNAME>/.local/share/Anki2/addons21/1463041493/libs/pygments/formatters/html.py", line 850, in format_unencoded
    for t, piece in source:
  File "/home/<USERNAME>/.local/share/Anki2/addons21/1463041493/libs/pygments/formatters/html.py", line 690, in _wrap_div
    for tup in inner:
  File "/home/<USERNAME>/.local/share/Anki2/addons21/1463041493/libs/pygments/formatters/html.py", line 708, in _wrap_pre
    for tup in inner:
  File "/home/<USERNAME>/.local/share/Anki2/addons21/1463041493/libs/pygments/formatters/html.py", line 727, in _format_lines
    for ttype, value in tokensource:
  File "/home/<USERNAME>/.local/share/Anki2/addons21/1463041493/libs/pygments/lexer.py", line 191, in streamer
    for _, t, v in self.get_tokens_unprocessed(text):
<class 'RuntimeError'>: generator raised StopIteration

NOTE

I have used a few different other lexers, including normal SQL (which doesn't work for the psql commands). It's only this lexer, so far, that is not working for me and the issue seems with that specific lexer.

Thanks.

100cube commented 4 years ago

Hi @glutanimate I just compared libs/pgments/lexers to upstream and noticed this repo is a bit behind. You might want to update the lexers when you get the chance.

Temporary workaround for anyone with similar problem

Backup the file /home/<USERNAME>/.local/share/Anki2/addons21/1463041493/libs/pygments/lexers/sql.py and replace it with this file. It seems working fine now for me.

Thanks again for your great work.