beancount-language-server
beancount-language-server copied to clipboard
fix: don't panic on invalid JSON inputs to Config
The server is set up to deal with empty journal_file
being provided in the configuration options, but not to handle configs that don't parse into a valid BeancountLspOptions
.
This meant that using the default config provided in nvim-lspconfig
: https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/beancount.lua would cause a panic on an invalid unwrap()
for a non-obvious reason: Lua serializes its empty table {}
as the JSON array []
instead of the JSON object {}
, causing the serde_json::from_value
call to fail.
It seemed that beancount-language-server
shouldn't panic if given a configuration that isn't useful.
Added some tests to indicate the expected behavior given these inputs.
NOTE:
Ideally it should log an error or warning to the user, but I wasn't sure how exactly we should be logging it, given that returning Err
from Config::update
would also panic because that's currently unwrap
-ed.