ycm-core / YouCompleteMe

A code-completion engine for Vim
http://ycm-core.github.io/YouCompleteMe/
GNU General Public License v3.0
25.36k stars 2.8k forks source link

Handle possible errors from RangeVisibleInBuffer() #4192

Closed bstaletic closed 9 months ago

bstaletic commented 9 months ago

PR Prelude

Thank you for working on YCM! :)

Please complete these steps and check these boxes (by putting an x inside the brackets) before filing your PR:

Why this change is necessary and useful

First and more common error is that by the time we execute

buffer = vim.buffers[ bufnr ]

the buffer might not be there any more. This is because RangeVisibleInBuffer() is called asynchronously and the user may bwipeout a buffer in between polls. This regularly happens in our vim tests. In such a case, we get a nasty traceback from vimsupport module. The solution is to catch the KeyError and return None.

However, ScrollingBufferRange() also was not ready to handle None values from RangeVisibleInBuffer(), even though RangeVisibleInBuffer() could return None even before, if a visible window for bufnr can not be found.

As for the missing tests... showing that an inherently racy scenario does not cause a stacktrace in vim level test... I think I prefer to keep what is left of my sanity.


This change is Reviewable

codecov[bot] commented 9 months ago

Codecov Report

Merging #4192 (4b3df69) into master (bf0dbea) will increase coverage by 0.10%. The diff coverage is 100.00%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #4192 +/- ## ========================================== + Coverage 88.90% 89.00% +0.10% ========================================== Files 34 34 Lines 4398 4403 +5 ========================================== + Hits 3910 3919 +9 + Misses 488 484 -4 ```
bstaletic commented 9 months ago

We seem not only to not catch traces during test teardown but not produce coverage either? The coverage part is probably ok, but not actually catching this KeyError in CI is odd.

mergify[bot] commented 9 months ago

Thanks for sending a PR!