Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle possible errors from RangeVisibleInBuffer() #4192

Merged

Conversation

bstaletic
Copy link
Collaborator

@bstaletic bstaletic commented Oct 4, 2023

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:

  • I have read and understood YCM's CONTRIBUTING document.
  • I have read and understood YCM's CODE_OF_CONDUCT document.
  • I have included tests for the changes in my PR. If not, I have included a
    rationale for why I haven't.
  • I understand my PR may be closed if it becomes obvious I didn't
    actually perform all of these steps.

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

@bstaletic bstaletic force-pushed the errors-from-range-visible-in-buffer branch from cb50e20 to 4b3df69 Compare October 4, 2023 04:59
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.
@codecov
Copy link

codecov bot commented Oct 4, 2023

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
@@            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
Copy link
Collaborator Author

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.

Copy link
Member

@puremourning puremourning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Cheers!

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: 1 of 2 LGTMs obtained (waiting on @bstaletic)

@bstaletic bstaletic added the Ship It! Manual override to merge a PR by maintainer label Oct 4, 2023
@mergify
Copy link
Contributor

mergify bot commented Oct 4, 2023

Thanks for sending a PR!

@mergify mergify bot merged commit 88ed5a7 into ycm-core:master Oct 4, 2023
12 of 13 checks passed
@bstaletic bstaletic deleted the errors-from-range-visible-in-buffer branch October 4, 2023 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ship It! Manual override to merge a PR by maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants