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

`E5113: Error while calling lua chunk: Vim:E739: Cannot create directory /tmp/gp_whisper: file already exists` #84

Closed kohane27 closed 6 months ago

kohane27 commented 6 months ago

Hello! Hope you're doing well. Thank you for creating this awesome llm plugin! I enjoy it a lot.

However, every time I start up my nvim I have the following error:

Error detected while processing /home/username/.config/nvim/init.lua:
E5113: Error while calling lua chunk: Vim:E739: Cannot create directory /tmp/gp_whisper: file already exists
stack traceback:
        [C]: in function 'mkdir'
        /home/username/.local/share/nvim/lazy/gp.nvim/lua/gp/init.lua:737: in function 'setup'
        /home/username/.config/nvim/lua/plugins/gp.lua:6: in main chunk
        [C]: in function 'require'
        /home/username/.config/nvim/init.lua:110: in main chunk
Press ENTER or type command to continue

My config:

require("gp").setup({
  openai_api_key = os.getenv("OPENAI_API_KEY"),
  cmd_prefix = "Gp",
  curl_params = { "--proxy", "http://127.0.0.1:8888" },
  whisper_dir = nil,
})

I thought adding the line whisper_dir = nil, would solve it, but it doesn't.

Any input is much appreciated. Thank you.

Robitx commented 6 months ago

@kohane27 Hey, nil won't help because in lua assigning a nil to a key in a map table removes the key from the table:

:lua print(vim.inspect({something = nil}))

will return {} and the setup function won't see whisper_dir inside the user conf at all.

In the latest version you could use for example empty table whisper_dir = {} to skip the folder creation, but I'd rather solve the underlying issue.

What system are you using? Could you run me an equivalent of:

$ ls -lah /tmp/ | grep gp_whisper
drwxr-xr-x  2 tibor users   40 Dec 20 13:13 gp_whisper

I'm able to emulate the bug on linux, if I manually make /tmp/gp_whisper a file instead of a dir.

kohane27 commented 6 months ago

@Robitx Thank you for getting back to me. I really appreciate it.

I'm now using whisper_dir = {}.

I'm on linux (Linux 6.6.7-arch1-1):

➜ ls -lah /tmp/ | grep gp_whisper
drwxr-xr-x     - username     21 Dec 11:07  gp_whisper/

Thank you again!

Robitx commented 6 months ago

@kohane27 yeah, no problem, sorry for not getting to it sooner.

I still don't understand it and it bugs me. :slightly_smiling_face: The /tmp/gp_whisper/ on your machine (I'm on arch too btw.) is clearly a dir.

The folder creation in gp uses the standard pattern:

    if vim.fn.isdirectory(dir) == 0 then
        M.info("creating directory " .. dir)
        vim.fn.mkdir(dir, "p")
    end

And the only way I could get to the same message is by creating the /tmp/gp_whisper as a file.

Are you able to replicate the bug if you rm -r /tmp/gp_whisper and start Neovim again? Or if you don't want to spent more time on it, we can close this and wait if someone with the same issue comes around.

kohane27 commented 6 months ago

@Robitx Thank you for getting back to me. I appreciate it.

I couldn't reproduce the issue after rm -r /tmp/gp_whisper. I tried the following:

require("gp").setup({
  openai_api_key = os.getenv("OPENAI_API_KEY"),
  cmd_prefix = "Gp",
  curl_params = { "--proxy", "http://127.0.0.1:8888" },
  -- whisper_dir = {},
})
  1. rm -f /tmp/gp_whisper /tmp/gp_images

  2. Open a file and get the following:

Gp: creating directory /tmp/gp_whisper
Gp: creating directory /tmp/gp_images
  1. Check with find /tmp -name 'gp*':
/tmp/gp_whisper
/tmp/gp_images
  1. Open a file and there is no error.

If I create /tmp/gp_whisper as a file then the error occurs.

I think it may be due to some migration? I installed gp.nvim quite some time ago and I think this project has undergone a lot of changes (I remember I saw some msg about gp.nvim upgrade.). So the migration period might have messed something up? Regardless, this problem doesn't exist anymore so I'll close it. If this bug creeps up again I'll re-open it.

Thank you again!