vim-highlightedyank icon indicating copy to clipboard operation
vim-highlightedyank copied to clipboard

A bug on matchdelete (E802: Invalid ID: -1)

Open wookayin opened this issue 5 years ago • 8 comments

I have no idea how to always reproduce it, but pretty often I run into the following error:

Error detected while processing function <SNR>247__doautocmd[7]..356[7]..<SNR>247__supercall[1]..350[3]..376[10]..378:
line    3:
E802: Invalid ID: -1 (must be greater than or equal to 1)

E802 is when matchdelete(v:val) receives an invalid argument (i.e. v:val = -1).

System information: Linux/Mac (both), neovim 0.4.3 (and on the latest nightly as well).

wookayin avatar Jan 27 '20 08:01 wookayin

In the s:highlight._quench_now() function (See this file):

 call map(self.id, 'matchdelete(v:val)')
 call filter(self.id, 'v:val > 0')

Shouldn't we first filter self.id and then call matchdelete?

wookayin avatar Jan 27 '20 08:01 wookayin

Another similar error that might happen from matchdelete():

Error detected while processing function <SNR>252_quench[5]..337:
line    8:
E803: ID not found: 7

wookayin avatar Jan 27 '20 08:01 wookayin

Hello, thank you for your report. I've tried on neovim v0.4.3, but unfortunately, I couldn't reproduce. It's easy to fiter ids equal to -1 before passing to matchdelete, however, in principle, it shouldn't happen. It seems something unexpected happened there. How often does this error happen? Could you make a minimum working vimrc?

machakann avatar Jan 28 '20 12:01 machakann

I also failed to come up with a minimal vimrc such that it can be consistently reproducible. I suspect there might be a conflict with other plugins, but no idea which one is in conflict. Do you have any other suggestion about how I can debug the plugin when the bug happens? On average, I experience this at least once a day.

wookayin avatar Jan 29 '20 08:01 wookayin

Thank you, don't mind about minimal vimrc. Is this your rc files?

machakann avatar Jan 30 '20 08:01 machakann

I might find the problem. Some plugins use clearmatches() which clears ALL highlights including others set. Probably, vim-highlightedyank tried to clear the highlight which was already cleared, and thus some inconsistency arose in internal states.

(I think plugin should not use the function since it affects globally, only be allowed manually or in tests.)

machakann avatar Jan 30 '20 09:01 machakann

I've added a check to avoid the above situation. It is already merged to master, please try. Please inform me if the problem still persists.

machakann avatar Jan 30 '20 09:01 machakann

By the way,

Another similar error that might happen from matchdelete():

Error detected while processing function <SNR>252_quench[5]..337:
line    8:
E803: ID not found: 7

this is probably from another plugin, maybe highlightedundo, I will update it, too. Thank you for using!

machakann avatar Jan 30 '20 09:01 machakann