elinks icon indicating copy to clipboard operation
elinks copied to clipboard

Add option to remove delay on scripting errors

Open AdrianVollmer opened this issue 1 year ago • 2 comments

I'm using elinks to render HTML messages in mutt. Recently, I noticed a delay when opening certain HTML messages. I traced it back to elinks, probably this line: https://github.com/rkd77/elinks/blob/d501d762eab59cc4e3cd432b25a36a60bc9aec91/src/scripting/scripting.c#L47

I also use python hooks for a different purpose, so they simply return the argument in this case, but this triggers the delay.

You can verify like so:

$ rm -rf ~/.config/elinks
# Create file in "wrong" encoding
$ echo '<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>Ö</body></html>' > test.html
$ iconv -f utf8 -t ISO8859-15 test.html > test-iso.html
$ touch .config/elinks/hooks.py
# This is quick
$ time elinks -dump test-iso.html  
elinks -dump test-iso.html  0.02s user 0.01s system 100% cpu 0.032 total
$ mkdir -p ~/.config/elinks && echo 'def pre_format_html_hook(url, html):\n  return html' > ~/.config/elinks/hooks.py
# This is slow
$ time elinks -dump test-iso.html
ELinks: [Python 3.12.5 error] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd6 in position 62: invalid continuation byte

   ╓
elinks -dump test-iso.html  0.03s user 0.01s system 1% cpu 3.039 total

I suppose the intent is that the error is loud so that the user notices. However, in this case, I'd rather have it fail silently and see a few corrupt characters. Or bail out entirely and return a non-zero exit code, then I would have found the issue sooner.

$ elinks --version
ELinks 0.18.GIT d501d762eab59cc4e3cd432b25a36a60bc9aec91
Built on Aug 26 2024 10:50:18

What do you think about making that sleep argument as an option, or maybe add an environment variable so I can control this? The error could also go to a log file or something.

(As a workaround I now pipe the file through iconv first to make sure it's always utf8.)

AdrianVollmer avatar Aug 26 '24 16:08 AdrianVollmer

Can be like this?

rkd77 avatar Aug 26 '24 18:08 rkd77

Works for me! Great, thanks

AdrianVollmer avatar Aug 27 '24 10:08 AdrianVollmer