From aaffd98d0ee2da1fa0131307d8b817f60a3185f7 Mon Sep 17 00:00:00 2001 From: Marc Schreiber Date: Tue, 31 Oct 2023 07:46:46 +0100 Subject: [PATCH] Handle Invalid JSON in Cargo Output When running all tests of a file, the cargo command prints none JSON strings into stdout. Therefore, the debugging fails because the dap.lua file wasn't prepared for that. This commit makes the JSON parsing of the stdout output more robust by excepting none JSON formatted lines. --- lua/rust-tools/dap.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/rust-tools/dap.lua b/lua/rust-tools/dap.lua index 3aa1b95..bc670e8 100644 --- a/lua/rust-tools/dap.lua +++ b/lua/rust-tools/dap.lua @@ -86,7 +86,10 @@ function M.start(args) local executables = {} for _, value in pairs(j:result()) do - local artifact = vim.fn.json_decode(value) + local ok, artifact = pcall(vim.fn.json_decode,value) + if not ok then + goto loop_end + end -- only process artifact if it's valid json object and it is a compiler artifact if