auto-save.nvim icon indicating copy to clipboard operation
auto-save.nvim copied to clipboard

nvim_buf_set_var can rise invalid buf error

Open doubleloop opened this issue 3 years ago • 3 comments
trafficstars

  • fix some whitespaces
  • fix: nvim_buf_set_var can rise invalid buf error ( #46 #48 #53 )

doubleloop avatar Aug 16 '22 13:08 doubleloop

I came here because I was having the same issue, but I think it might be better solved like this instead of using pcall:

   elseif api.nvim_buf_is_valid(buf) then
      api.nvim_buf_set_var(buf, 'autosave_' .. name, value)
   end

danielfalk avatar Aug 25 '22 12:08 danielfalk

@danielfalk I am not a specialist on vim buffer but can there be race condition? I mean can buffer become invalid between calling nvim_buf_is_valid and api.nvim_buf_set_var? If no then your approach may be better, if yes, then pcall is better.

Also note that pcall is already used in similar case so it might be more consistent to use it

doubleloop avatar Aug 25 '22 23:08 doubleloop

@danielfalk I am not a specialist on vim buffer but can there be race condition? I mean can buffer become invalid between calling nvim_buf_is_valid and api.nvim_buf_set_var? If no then your approach may be better, if yes, then pcall is better.

Also note that pcall is already used in similar case so it might be more consistent to use it

Neither am I! Just a suggestion because as far as I know, this isn't multi-threaded and the code runs synchronously, but I don't know for sure.

danielfalk avatar Aug 26 '22 11:08 danielfalk