Robitx / gp.nvim

Gp.nvim (GPT prompt) Neovim AI plugin: ChatGPT sessions & Instructable text/code operations & Speech to text [OpenAI]
MIT License
537 stars 50 forks source link

bug: `nil` value indexing on emtpy string response #70

Closed kunzaatko closed 7 months ago

kunzaatko commented 7 months ago

When the response is empty, the on_exit function indexes a nil value of the first_line (flc) (and the last_line (llc) is also a nil value)

Message:

Gp: OpenAI query response is empty:
""
Press ENTER or type command to continue
Error executing vim.schedule lua callback: ...kunzaatko/.local/share/nvim/lazy/gp.nvim/lua/gp/init.lua:2434: attempt to index local 'flc' (a nil
value)
stack traceback:
        ...kunzaatko/.local/share/nvim/lazy/gp.nvim/lua/gp/init.lua:2434: in function 'on_exit'
        ...kunzaatko/.local/share/nvim/lazy/gp.nvim/lua/gp/init.lua:2590: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

Possible solution

The function can be returned from preemptively if the response is an empty string.

kunzaatko commented 7 months ago

I wanted to PR the suggested solution, but I wasn't sure, which of the variables is the response.

Robitx commented 7 months ago

@kunzaatko diky Martine. :slightly_smiling_face: