From 81067b31aae0f27039cae3106cc27ec97dd34700 Mon Sep 17 00:00:00 2001 From: Xiaochao Dong Date: Thu, 27 Feb 2025 11:44:24 +0800 Subject: [PATCH] fix(copilot): fail to decode the empty token file (#1414) --- lua/avante/providers/copilot.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/avante/providers/copilot.lua b/lua/avante/providers/copilot.lua index 988ab04..b792723 100644 --- a/lua/avante/providers/copilot.lua +++ b/lua/avante/providers/copilot.lua @@ -284,7 +284,10 @@ function M.setup_file_watcher() {}, vim.schedule_wrap(function() -- Reload token from file - if copilot_token_file:exists() then M.state.github_token = vim.json.decode(copilot_token_file:read()) end + if copilot_token_file:exists() then + local ok, token = pcall(vim.json.decode, copilot_token_file:read()) + if ok then M.state.github_token = token end + end end) ) end