jghauser/papis.nvim

`read_yaml` should fail gracefully if yaml is malformatted

maxmahlke opened this issue · 1 comments

I got a rather ugly error message when my database was being built (did not save the traceback) which was due to a malformatted yaml file. I had to go through the traceback and add log.debug(filepath) to see which file was broken.

I suggest that in this function below

local function read_yaml(path)
log.trace("Reading path: " .. path)
local filepath = Path:new(path)
local entry = lyaml.load(filepath:read())
return entry
end

we add

  1. Catch the error: if read_yaml fails, just continue with the next one
  2. A notify and log.debug event: notify the user which file failed

Edit: Found the error traceback here

| Error detected while processing BufEnter Autocommands for "*.tex":
|| Error executing lua callback: 6:11: did not find expected key
|| stack traceback:
|| 	[C]: in function 'error'
|| 	...acker_hererocks/2.1.0-beta3/share/lua/5.1/lyaml/init.lua:306: in function 'error'
|| 	...acker_hererocks/2.1.0-beta3/share/lua/5.1/lyaml/init.lua:325: in function 'parse'
|| 	...acker_hererocks/2.1.0-beta3/share/lua/5.1/lyaml/init.lua:443: in function 'load_node'
|| 	...acker_hererocks/2.1.0-beta3/share/lua/5.1/lyaml/init.lua:340: in function 'load_node'
|| 	...acker_hererocks/2.1.0-beta3/share/lua/5.1/lyaml/init.lua:393: in function 'load_node'
|| 	...acker_hererocks/2.1.0-beta3/share/lua/5.1/lyaml/init.lua:378: in function 'load_node'
|| 	...acker_hererocks/2.1.0-beta3/share/lua/5.1/lyaml/init.lua:497: in function 'load'
|| 	...e/pack/packer/opt/papis.nvim/lua/papis/papis-storage.lua:90: in function 'read_yaml'
|| 	...e/pack/packer/opt/papis.nvim/lua/papis/papis-storage.lua:149: in function 'get_data_full'
|| 	.../nvim/site/pack/packer/opt/papis.nvim/lua/papis/data.lua:54: in function 'update_main_tbls'
|| 	.../nvim/site/pack/packer/opt/papis.nvim/lua/papis/data.lua:124: in function 'sync_storage_data'
|| 	.../nvim/site/pack/packer/opt/papis.nvim/lua/papis/data.lua:158: in function 'sync_db'
|| 	.../nvim/site/pack/packer/opt/papis.nvim/lua/papis/init.lua:103: in function <.../nvim/site/pack/packer/opt/papis.nvim/lua/papis/init.lua:49>

Hey! Sorry, somehow this slipped under the radar! Fixing it now! I'm making a note to add a test to check for such failures. Thanks!