-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore non-json lines when parsing json output #54
Conversation
Is there anything preventing us from merging this? |
Hi @olzhasar, thanks for your time to contribute! I need more time to understand what problem does this PR fixes. You didn't provide clear steps to reproduce the issue respectively I need to understand problem context on my own. Also I need to check if your change doesn't break any tests. I would be great if you can add your own test cases for the issue. I will try to take closer look on the weekend. Also I have plans to add unit test step to our github action and add a template for open issue. It will simplify a lot of things. Sorry for the delay |
@sergii4 I can confirm I also see this behavior, when using Go provided by pkgx but not when provided by Homebrew. It seems there are various reports about not being able to parse the JSON output and likely because of different root causes. In my case, the problem stems from pkgx, but this may not be the case in the other reported issues. But it seems that something is prone to injecting stuff which cannot be parsed by neotest-go for others as well, so I think this fix is a good one. The fix provided by @olzhasar fixes this problem reported in #52, #53 and #68. I added the following to the output.lua file: diff --git a/lua/neotest-go/output.lua b/lua/neotest-go/output.lua
index f23ebd9..47dc76a 100644
--- a/lua/neotest-go/output.lua
+++ b/lua/neotest-go/output.lua
@@ -27,6 +27,10 @@ function M.marshal_gotest_output(lines)
local tests = {}
local log = {}
local testfile, linenumber
+
+ -- print all lines in one print command
+ print(table.concat(lines, "\n"))
+
for _, line in ipairs(lines) do
if line ~= "" then
local ok, parsed = pcall(vim.json.decode, line, { luanil = { object = true } }) And this is what Neovim prints with Go provided by Homebrew when running a test (all fine):
But this is what is printed when using Go provided by pkgx (note the first line, where you now have
By applying the same fix as proposed by @olzhasar I no longer have this issue with neotest-go. Please consider merging this PR. |
Hi, pkgx here.
Thanks! |
I'll let @sergii4 answer this properly (which I am guessing is one of the maintainers of this repo?) but ... I believe the neotest-go adapter only constructs the command to be executed and then it is in fact neotest that executes the command. My guess is it's all in here: https://github.com/nvim-neotest/neotest/blob/1ee3fcc150207f33dba8c9b3f478e5a0148d661d/lua/neotest/lib/process/init.lua I can't quite make out whether it is Neovim, neotest or neotest-go that is identifying as a tty here, and makes the |
@fredrikaverpil I am not sure I understand what the question is. What problem have you faced? Did you realise what the root cause is? I see you left a bunch of comments recently so I am a bit lost |
@fredrikaverpil I assume it would be nice to reproduce the problem, apply fix then check if it works before merge it. What do you think? |
@fredrikaverpil my question is how this
fixes problem with |
@sergii4 yes, so let me break this down a bit. I understand there might be multiple issues at play here, which all result in the same symptom; having neotest-go fail an otherwise passing test because of a failure to parse the Observations
My specific caseAlso reported in #68 and perhaps prematurely closed due to thinking it was a duplicate (which it likely isn't). In my case, I've installed Go using pkgx: brew install pkgx
pkgx install go@latest This downloads Go of the latest version and creates a shim in I can then successfully run Having this said, note that in #52 (comment) it is mentioned that something similar happens, but not because of pkgx. Some kind of check is likely warrantedI mentioned this over at pkgx discussions, and the question arose on whose fault this all actually is. Is it pkgx, neovim, neotest or neotest-go which is at fault here? It's interesting to try and iron that out - but in the end, there are at least 3 different reported issues and one open PR about the problem in the neotest-go project about this. To me, this indicates that there's likely different issues at play here, which may (or may not) have its root cause in different places. But all in all, it doesn't seem bad to have some sort of check in place to make sure to only process lines that seems to be a valid JSON line (before attempting to process). Because I don't think there's a concept of "try/catch" in Lua? Maybe checking whether the line to be processed is not empty and starts with |
@fredrikaverpil thanks for proper intro! I confirm that I was able to reproduce it. Looking further |
@sergii4 Even if you find this not to be a 100% perfect fix, would you please consider merging this? |
Hi @fredrikaverpil, I have found the root cause. Neotest itself runs command with
Setting pty = false made the go test command behave as if it was running in a non-interactive environment (like being piped or redirected), which in our case led to cleaner JSON output without the extra terminal control sequences. Your can easily reproduce it by yourself running
The script command is commonly used to record terminal sessions, but it also runs commands in a pseudo-terminal. You can check that in output file first line is something like:
which breaks parsing down the call. I am not sure how to mitigate it so far so I just merged the PR @mxcl it turned out that the parent project runs it with @olzhasar sorry for long review. I just didn't want to approve it blindly because such approach can lead to further bugs. Despite your PR didn't change since you opened it at the moment we have full understanding that the issue isn't caused by us. |
Fixes #53