0

When debugging Vim plugin you may be confronted to error messages of the kind:

Error detected while processing function GrandFather[2]..Father[5]..Son
Line    6:
E484: Can't open file foo.txt

What does it means and how to identify the corresponding line of codes?

2 Answers 2

1

(shameless plug)

In lh-vim-lib I provide a (i18n robust, on *nix at least) set of functions to decode stacktraces/callstacks. If your objective is to decode stacktraces displayed on errors, I recommend to wrap it in a command.

" .vimrc
" Parameter: number of errors to decode, default: "1"
command! -nargs=? WTF call lh#exception#say_what(<f-args>)
4
  • Thanks :-) I'll give it a try! Mar 29 at 17:25
  • Hi @Luc, it seems to work very good thank you. Although to make it running on Windows with Vim 9.0 I had to replace <q-args> by <f-args> Mar 30 at 13:21
  • 1
    @VivianDeSmedt Thanks. I never remember which of the <*-args> is the correct one ^^' Mar 30 at 13:44
  • The problem with <q-args> is that if there is no argument it become "" and the code fails with eval("") you don't have the problem with <f-args>. Maybe could you also update GitHub. If you want I can propose a Pull Request if it helps. Mar 30 at 14:04
0

It means you have the following call stack:

Sun:6 E484: Can't open file foo.txt
Father:5
GrandFather:2

The GrandFather function calls the Father function at line 2.

Where line 1 is the first line of the GrandFather function right after the beginning of declaration of the function.

The Father function call the Sun function at line 5.

The Son function fails at line 6 with the error E484.

You can get more information about error E484 by using the command :help E484.

    0 function! Son(
    1    \ filename
    2    \ )
    3   " Read the file if possible
    4   echo "foo"
    5     \ . " bar"
 -> 6   call 
    7     \ readfile(a:filename)
    8 endfunction
     
    0 function! Father(
    1   \ filename
    2   \ )
    3   " Call Son:
    4   " That will read a file
 -> 5   call Son(a:filename)
    6 endfunction
     
    0 function! GrandFather(filename)
    1   " Call Father:
 -> 2   call Father(a:filename)
    3 endfunction 

You can find where (filename, linenb) a function is defined using the Vim command: :verbose function.

e.g.:

:verbose function GrandFather

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.