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

fix: reloading an modifiable octo buffer may cause a runtime error #812

Merged
merged 1 commit into from
Jan 19, 2025

Conversation

ldelossa
Copy link
Contributor

@ldelossa ldelossa commented Jan 19, 2025

fix: reloading an modifiable octo buffer may cause a runtime error

Fixes: #811

```
Error executing vim.schedule lua callback: ...hare/nvim/site/pack/deps/opt/octo.nvim/lua/octo/init.lua:111: Error executing lua: .
..hare/nvim/site/pack/deps/opt/octo.nvim/lua/octo/init.lua:119: Cursor position outside buffer
stack traceback:
        [C]: in function 'nvim_win_set_cursor'
        ...hare/nvim/site/pack/deps/opt/octo.nvim/lua/octo/init.lua:119: in function <...hare/nvim/site/pack/deps/opt/octo.nvim/lu
a/octo/init.lua:111>
        [C]: in function 'nvim_buf_call'
        ...hare/nvim/site/pack/deps/opt/octo.nvim/lua/octo/init.lua:111: in function 'cb'
        ...hare/nvim/site/pack/deps/opt/octo.nvim/lua/octo/init.lua:150: in function 'cb'
        ...e/nvim/site/pack/deps/opt/octo.nvim/lua/octo/gh/init.lua:163: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
stack traceback:
        [C]: in function 'nvim_buf_call'
        ...hare/nvim/site/pack/deps/opt/octo.nvim/lua/octo/init.lua:111: in function 'cb'
        ...hare/nvim/site/pack/deps/opt/octo.nvim/lua/octo/init.lua:150: in function 'cb'
        ...e/nvim/site/pack/deps/opt/octo.nvim/lua/octo/gh/init.lua:163: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

```

The above runtime error can occur when an Octo buffer is modified and
then a reload command is used.

The issue occurs when capturing the initial cursor position before
reload of the Octo buffer.

The initial cursor position may be in an invalid position in the current
Octo buffer by the time the reloaded buffer is loaded int.

Simply get the lines of the newly loaded buffer and only cursor reset at
the minimum valid row position.

The real-world reason to fix this is to avoid a subtly but possibly
annoying runtime error when the user performs "Octo comment add" in an
issue buffer and then reloads the buffer without submitting the comment.

Describe what this PR does / why we need it

Fixes a runtime error when reloading modified Octo buffers

Does this pull request fix one issue?

Fixes: #811

Describe how you did it

Simply get the lines of the newly loaded buffer and only cursor reset at
the minimum valid row position.

The real-world reason to fix this is to avoid a subtly but possibly
annoying runtime error when the user performs "Octo comment add" in an
issue buffer and then reloads the buffer without submitting the comment.

Describe how to verify it

Ensured cursor reset works both when Octo buffer is not modified and when modified (add a couple new lines to Octo buffer before reload).

Special notes for reviews

Checklist

  • Passing tests and linting standards
  • Documentation updates in README.md and doc/octo.txt

Fixes: pwntester#811

```
Error executing vim.schedule lua callback: ...hare/nvim/site/pack/deps/opt/octo.nvim/lua/octo/init.lua:111: Error executing lua: .
..hare/nvim/site/pack/deps/opt/octo.nvim/lua/octo/init.lua:119: Cursor position outside buffer
stack traceback:
        [C]: in function 'nvim_win_set_cursor'
        ...hare/nvim/site/pack/deps/opt/octo.nvim/lua/octo/init.lua:119: in function <...hare/nvim/site/pack/deps/opt/octo.nvim/lu
a/octo/init.lua:111>
        [C]: in function 'nvim_buf_call'
        ...hare/nvim/site/pack/deps/opt/octo.nvim/lua/octo/init.lua:111: in function 'cb'
        ...hare/nvim/site/pack/deps/opt/octo.nvim/lua/octo/init.lua:150: in function 'cb'
        ...e/nvim/site/pack/deps/opt/octo.nvim/lua/octo/gh/init.lua:163: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
stack traceback:
        [C]: in function 'nvim_buf_call'
        ...hare/nvim/site/pack/deps/opt/octo.nvim/lua/octo/init.lua:111: in function 'cb'
        ...hare/nvim/site/pack/deps/opt/octo.nvim/lua/octo/init.lua:150: in function 'cb'
        ...e/nvim/site/pack/deps/opt/octo.nvim/lua/octo/gh/init.lua:163: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

```

The above runtime error can occur when an Octo buffer is modified and
then a reload command is used.

The issue occurs when capturing the initial cursor position before
reload of the Octo buffer.

The initial cursor position may be in an invalid position in the current
Octo buffer by the time the reloaded buffer is loaded int.

Simply get the lines of the newly loaded buffer and only cursor reset at
the minimum valid row position.

The real-world reason to fix this is to avoid a subtly but possibly
annoying runtime error when the user performs "Octo comment add" in an
issue buffer and then reloads the buffer without submitting the comment.

Signed-off-by: ldelossa <[email protected]>
@wd60622 wd60622 added the bug Something wrong in the code label Jan 19, 2025
@wd60622 wd60622 merged commit 916932d into pwntester:master Jan 19, 2025
3 checks passed
@wd60622
Copy link
Collaborator

wd60622 commented Jan 19, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something wrong in the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cursor reset on reload may cause runtime error if Octo buffer was modified.
2 participants