rodjek / vim-puppet

Puppet niceties for your Vim setup
Apache License 2.0
501 stars 137 forks source link

if puppet_display_errors is not defined in .vimrc the plugin thrown an error #151

Closed shadowwa closed 2 weeks ago

shadowwa commented 3 weeks ago

while testing the latest version I got:

Error detected while processing BufRead Autocommands for "*.epp"..FileType Autocommands for "epuppet"..function <SNR>22_lod_ft[2]..<SNR>22_lod[16]..<SNR>22_source[4]..script /home/shad/.vim/plugged/vim-puppet/syntax/epuppet.vim[47]../h
ome/shad/.vim/plugged/vim-puppet/syntax/puppet.vim:
line  285:
E121: Undefined variable: g:puppet_display_errors
Press ENTER or type command to continue

As soon as I add, in my .vimrc:

let g:puppet_display_errors = <anything>

the error disappear

lelutin commented 2 weeks ago

oops! thanks for testing the new code!

the fix is actually simple: I forgot to set the default value in ftplugin/epuppet.vim I'll push that now

lelutin commented 2 weeks ago

err huh.. actually ftplugin/epuppet.vim does runtime! ftplugin/puppet.vim at line 80, so the variable should have its default value..

@shadowwa @dmaes what version of vim/nvim are you using?

I also kinda wonder if using v:true is what's problematic for some versions.. could you try to comment out the variable in your vimrc and then apply the following changes:

in ftplugin/puppet.vim line 26:

-   let g:puppet_display_errors = v:true
+   let g:puppet_display_errors = 1

in syntax/puppet.vim line 285:

-if g:puppet_display_errors ==# v:true
+if g:puppet_display_errors ==# 1
shadowwa commented 2 weeks ago

I'm using vim version 9.1-719, I also get the same error with 9.1.0016 from ubuntu noble and 9.1-719 from mageia. changing v:true to 1 in both file still show the same error

I've just tested with neovim and got: nvim v0.9.5 (ubuntu noble) does not show this error but with nvim v0.10.1 (mageia) I got the following error

Error detected while processing BufReadPost Autocommands for "*":                                                                                                                                                                          
Error executing lua callback: /usr/share/nvim/runtime/filetype.lua:35: Error executing lua: /usr/share/nvim/runtime/filetype.lua:36: BufReadPost Autocommands for "*"..FileType Autocommands for "puppet"..function <SNR>6_lod_ft[2]..<SNR>
6_lod[16]..<SNR>6_source[4]..script /home/shad/.local/share/nvim/plugged/vim-puppet/syntax/puppet.vim, line 285: Vim(if):E121: Undefined variable: g:puppet_display_errors                                                                 
stack traceback:                                                                                                                                                                                                                           
        [C]: in function 'nvim_cmd'                                                                                                                                                                                                        
        /usr/share/nvim/runtime/filetype.lua:36: in function </usr/share/nvim/runtime/filetype.lua:35>                                                                                                                                     
        [C]: in function 'nvim_buf_call'                                                                                                                                                                                                   
        /usr/share/nvim/runtime/filetype.lua:35: in function </usr/share/nvim/runtime/filetype.lua:10>                                                                                                                                     
stack traceback:                                                                                                                                                                                                                           
        [C]: in function 'nvim_buf_call'                                                                                                                                                                                                   
        /usr/share/nvim/runtime/filetype.lua:35: in function </usr/share/nvim/runtime/filetype.lua:10>                                                                                                                                     
Press ENTER or type command to continue

in both case, vim-puppet is loaded with vim-plug

Plug 'rodjek/vim-puppet', { 'for': ['puppet', 'epuppet'] }
dmaes commented 2 weeks ago

Same error when using 1 instead of v:true. Issue happens with both puppet and epuppet files.

> ~ $ vim --version
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Aug 31 2024 21:12:10)
Included patches: 1-707
Compiled by Arch Linux
Huge version without GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       +tcl/dyn
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        +terminal
-autoservername    -footer            -mzscheme          +terminfo
-balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term +gettext           +num64             +textobjects
-browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     +perl/dyn          +title
+channel           +ipv6              +persistent_undo   -toolbar
+cindent           +job               +popupwin          +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall           +python3/dyn       +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
+cscope            +localmap          +ruby/dyn          +wildignore
+cursorbind        +lua/dyn           +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con        +mksession         +smartindent       +writebackup
+diff              +modify_fname      -sodium            -X11
+digraphs          +mouse             -sound             +xattr
-dnd               -mouseshape        +spell             -xfontset
-ebcdic            +mouse_dec         +startuptime       -xim
+emacs_tags        +mouse_gpm         +statusline        -xpm
+eval              -mouse_jsbterm     -sun_workshop      -xsmp
+ex_extra          +mouse_netterm     +syntax            -xterm_clipboard
+extra_search      +mouse_sgr         +tag_binary        -xterm_save
-farsi             -mouse_sysmouse    -tag_old_static
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
 3rd user vimrc file: "$XDG_CONFIG_HOME/vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -g -ffile-prefix-map=/build/vim/src=/usr/src/debug/vim -flto=auto -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.38/core_perl/CORE -Wl,-O1 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-z,pack-relative-relocs -flto=auto -L/usr/local/lib -o vim -lm -ltinfo -lacl -lattr -lgpm -L/usr/lib -ltclstub8.6 -ldl -lz -lpthread -lm

Not using any plugin manager, just cloning straight into packdir.

dmaes commented 2 weeks ago

Sprinkling in some echom statements, it seems that syntax/puppet.vim runs before ftplugin/puppet.vim, so g:puppet_display_errors is still undefined in syntax/puppet.vim.

In my vimrc, I have

syntax on
filetype plugin indent on

Placing syntax on after filetype ... makes for correct order of loading the files, and removes the error.

shadowwa commented 2 weeks ago

Even having syntax on after filetype plugin indent on in my .vimrc does not solve the problem. But :scriptnames show me that the order is the problematic one

109: ~/.vim/plugged/vim-puppet/syntax/puppet.vim
110: ~/.vim/plugged/vim-puppet/ftplugin/puppet.vim
lelutin commented 2 weeks ago

thanks both for the tests and feedback!

I took some time to dig around other plugins to see how they do things and variables that are used only in the syntax script apparently get their default value defined there.

I've just create pull request #152 to hopefully fix this for both of you. could I ask you to try that code out, see if it removes the error?

shadowwa commented 2 weeks ago

No more error with this fix.

lelutin commented 2 weeks ago

very nice! thanks for testing. I'll merge that in right now