junegunn / fzf.vim

fzf :heart: vim
MIT License
9.65k stars 584 forks source link

:Files gives error [Command failed: cat '/tmp/v8STSj8/13'] #1301

Closed manaskarekar closed 3 years ago

manaskarekar commented 3 years ago

I am new to fzf.vim and it has changed my life. Thank you for this.

I'm using it pretty much as it came except for some shortcuts.

(I did not try the minimal configuration yet, because the problem arises after some time when tmp files are cleared. Although I will leave an instance running to try and replicate the issue).

I looked through issues #996, #260, #642, and some more without a clear answer.


So the issue is that :Files command works great for some time. After some amount of use though, when I try to use :Files, it fails with a failure to cat some now-cleared tmp file.

[Command failed: cat '/tmp/v8STSj8/13']

When I go to the tmp folder and check, the file is indeed missing and there's usually a different file, like some higher number than 13 in this case.

As expected, restarting vim fixes the issue but only till the next time it fails. Once it has failed, it is not possible to get it to work without restarting vim.

Any help appreciated!

Thank you.

junegunn commented 3 years ago

After some amount of use

How much time? Maybe your system is clearing up temp directories Vim was using every few days.

cat /usr/lib/tmpfiles.d/tmp.conf
jreybert commented 3 years ago

I encounter the same issue.

With vim 7.4, I get the following behavior.

With vim 8.0, the behavior is sighlty different:

Anyway, I just use :Files command, I don't get any errors.

jreybert commented 3 years ago

in fzf (not fzf.vim), reverting to junegunn/fzf@7411da8d5a37b94b2171920c82c0dafe6f9115b6~1 seems to fix the issue. junegunn/fzf@7411da8d5a37b94b2171920c82c0dafe6f9115b6 seems to be the culprit here.

manaskarekar commented 3 years ago

After some amount of use

How much time? Maybe your system is clearing up temp directories Vim was using every few days.

cat /usr/lib/tmpfiles.d/tmp.conf

Sorry I didn't see your post until now. I thought that may be the case, but it didn't seem to happen after a set amount of time. It happens, as @jreybert mentioned, after using the buffers command and then trying to use the files command.

wendx commented 3 years ago

I also encountered the same problem. After executing the command :BTags and then executing :FZF this error occurred: [command failed: cat '/tmp/vYylukm/10']

Rolling back to junegunn/fzf@7411da8 also can not solve the exception。

jreybert commented 3 years ago

@wendx you must roll back to junegunn/fzf@7411da8~1 (1 commit before) which is junegunn/fzf@3f75a8369f63f2bd6ac3686fc5d88f2bc128e610

wendx commented 3 years ago

@wendx you must roll back to junegunn/fzf@7411da8~1 (1 commit before) which is junegunn/fzf@3f75a83

@jreybert Rolling back to junegunn/fzf@3f75a83 is still abnormal. Do I need other operations after the rollback?

jreybert commented 3 years ago

No other operation on my side. It works and improve things on two different setups (vim 7.4 and vim 8.0)

jw-mcgrath commented 3 years ago

Thanks @jreybert this worked for me!

junegunn commented 3 years ago

I can't reproduce the problem. Can you check if you still have the issue with the following minimal vimrc?

vim -Nu <(curl https://gist.githubusercontent.com/junegunn/6936bf79fedd3a079aeb1dd2f3c81ef5/raw)

(https://gist.githubusercontent.com/junegunn/6936bf79fedd3a079aeb1dd2f3c81ef5/raw)

wendx commented 3 years ago

I can't reproduce the problem. Can you check if you still have the issue with the following minimal vimrc?

vim -Nu <(curl https://gist.githubusercontent.com/junegunn/6936bf79fedd3a079aeb1dd2f3c81ef5/raw)

(https://gist.githubusercontent.com/junegunn/6936bf79fedd3a079aeb1dd2f3c81ef5/raw)

There are still exceptions when using this .vimrc. The operation process is as follows: (1) open file : FZF (2) jump to function : BTags (A prompt message appears:Vim(unlet):E488: Trailing characters) (3) encountered an exception while trying to open another file : FZF (A prompt message appears:[Command failed: cat '/tmp/vsirqvi/10'])

wendx commented 3 years ago

I can't reproduce the problem. Can you check if you still have the issue with the following minimal vimrc?

vim -Nu <(curl https://gist.githubusercontent.com/junegunn/6936bf79fedd3a079aeb1dd2f3c81ef5/raw)

(https://gist.githubusercontent.com/junegunn/6936bf79fedd3a079aeb1dd2f3c81ef5/raw)

There are still exceptions when using this .vimrc. The operation process is as follows: (1) open file : FZF (2) jump to function : BTags (A prompt message appears:Vim(unlet):E488: Trailing characters) (3) encountered an exception while trying to open another file : FZF (A prompt message appears:[Command failed: cat '/tmp/vsirqvi/10'])

After I restore my own .vimrc, there will be no more exceptions. I don't understand the reason. (I rolled back to junegunn/fzf@3f75a83 )

SelvamArul commented 3 years ago

rolling back to junegunn/fzf@3f75a83 solves the issue for me

junegunn commented 3 years ago

What's your $SHELL and &shell?

" From vim
:echo &shell
:echo $SHELL

If you get /some/shell, does /some/shell -c "cat '/some/file'" work as expected?

wendx commented 3 years ago

What's your $SHELL and &shell?

" From vim
:echo &shell
:echo $SHELL

If you get /some/shell, does /some/shell -c "cat '/some/file'" work as expected?

I think we are about to find out the cause of the abnormality. The test is as follows: Normal condition:

:echo &shell
/bin/bash
:echo $SHELL
/bin/bash

After executing the command ‘:BTags’:

:echo &shell
sh
:echo $SHELL
/bin/bash

It can be executed normally as follows: sh -c "cat ~/.vimrc"

If you execute the command as follows, an error will be reported:

sh -c "cat '~/.vimrc'"
cat: '~/.vimrc': No such file or directory
junegunn commented 3 years ago
  1. :BTags (or any command) should restore the original &shell on completion. I'm not sure how you ended up with sh. Do you have the latest version of the main fzf plugin? (not fzf.vim but fzf)
  2. cat '~/.vimrc' is not a valid command. The single-quotation prevents the shell from expanding ~. :Files command will not yield a path with ~, so this is unrelated to the problem.
wendx commented 3 years ago
  1. :BTags (or any command) should restore the original &shell on completion. I'm not sure how you ended up with sh. Do you have the latest version of the main fzf plugin? (not fzf.vim but fzf)

  2. cat '~/.vimrc' is not a valid command. The single-quotation prevents the shell from expanding ~. :Files command will not yield a path with ~, so this is unrelated to the problem.

The version I use is:3f90fb42d8871920138ace9878502f22a4d91e85 I updated to the latest version, and the problem still exists:179993f0cd79c6d1ec88981084ed04090e4f77f2 (:BTags ended up with sh) Fzf.vim has also been updated to the latest version: e393108bfae7ab308aa6ea38e0df19253cdc8499

junegunn commented 3 years ago

Can you apply this patch to the main fzf plugin and see if a tab opens with the input list when you run into the error?

diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index 4190e0e..0af01d0 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -473,6 +473,8 @@ try
       let temps.input = s:fzf_tempname()
       call writefile(source, temps.input)
       let source_command = (s:is_win ? 'type ' : 'cat ').fzf#shellescape(temps.input)
+      execute 'tabedit' temps.input
+      tabprevious
     else
       throw 'Invalid source type'
     endif
wendx commented 3 years ago

Can you apply this patch to the main fzf plugin and see if a tab opens with the input list when you run into the error?

diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index 4190e0e..0af01d0 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -473,6 +473,8 @@ try
       let temps.input = s:fzf_tempname()
       call writefile(source, temps.input)
       let source_command = (s:is_win ? 'type ' : 'cat ').fzf#shellescape(temps.input)
+      execute 'tabedit' temps.input
+      tabprevious
     else
       throw 'Invalid source type'
     endif

After executing the command: BTags, and then executing the command: FZF, an exception will still occur.. At this time, execute ": q" to close the file, and it will automatically open the file"/tmp/vbHrDm0/10". If the command ": BTags" is not executed, it will not appear.

junegunn commented 3 years ago

execute ": q" to close the file, and it will automatically open the file

I think you're confused here. The file is already opened in a different "tab" before you close the current buffer on the current tab with :q. You can hit gt to move between the tabs.

I'm trying to see if the temporary file is properly created with proper contents when you run :BTags.

junegunn commented 3 years ago

So two things to check:

  1. What does :echo $FZF_DEFAULT_COMMAND report after you run into the problem?
  2. Which version of Vim or Neovim are you running? Have you tried upgrading it?
wendx commented 3 years ago

So two things to check:

  1. What does :echo $FZF_DEFAULT_COMMAND report after you run into the problem?
  2. Which version of Vim or Neovim are you running? Have you tried upgrading it?

1.:echo $FZF_DEFAULT_COMMAND report:cat '/tmp/vhYEigb/17' 2.My current version VIM is:version 7.4.1689,I use VIM on our company's server and do not have administrator rights, so I cannot upgrade it.

junegunn commented 3 years ago

That could be a bug of Vim. I remember Neovim had a similar bug in the past. Have you ever run into the same problem on a newer version of Vim (8 or above)?

junegunn commented 3 years ago

Okay, it looks like unlet $FZF_DEFAULT_COMMAND doesn't work at all on Vim 7.4.

Can you test this patch?

diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index 4190e0e..b17361d 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -519,7 +519,8 @@ finally
     if len(prev_default_command)
       let $FZF_DEFAULT_COMMAND = prev_default_command
     else
-      execute 'unlet $FZF_DEFAULT_COMMAND'
+      let $FZF_DEFAULT_COMMAND = ''
+      silent! execute 'unlet $FZF_DEFAULT_COMMAND'
     endif
   endif
   let [&shell, &shellslash, &shellcmdflag, &shellxquote] = [shell, shellslash, shellcmdflag, shellxquote]
wendx commented 3 years ago

Okay, it looks like unlet $FZF_DEFAULT_COMMAND doesn't work at all on Vim 7.4.

Can you test this patch?

diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index 4190e0e..b17361d 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -519,7 +519,8 @@ finally
     if len(prev_default_command)
       let $FZF_DEFAULT_COMMAND = prev_default_command
     else
-      execute 'unlet $FZF_DEFAULT_COMMAND'
+      let $FZF_DEFAULT_COMMAND = ''
+      silent! execute 'unlet $FZF_DEFAULT_COMMAND'
     endif
   endif
   let [&shell, &shellslash, &shellcmdflag, &shellxquote] = [shell, shellslash, shellcmdflag, shellxquote]

This patch can fix the issue. BTW:I tested it on the VIM version 8.0.1453, and the exception also exists. Rolling back to: 3f75a8369f63f2bd6ac3686fc5d88f2bc128e610 can solve the problem. @jreybert also mentioned earlier that he tested it on vim8.