NeogitOrg / neogit

An interactive and powerful Git interface for Neovim, inspired by Magit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Neogit tab fails to load

abusch opened this issue · comments

Description

Not quite sure where the fault lies, but I just upgraded a bunch of plugins, including neogit, and trying to open neogit fails with the following message:

...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...ch/.local/share/nvim/lazy/neogit/lua/neogit/lib/json.lua:63: Failed to parse log json!: Expected value but found invalid token at character 22657
t\":\"dmy","wgMonthNames":["",<\>n"January","February","March",
stack traceback:
	[C]: in function 'error'
	...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: in function 'callback_or_next'
	...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:45: in function 'cb'
	...sch/.local/share/nvim/lazy/neogit/lua/neogit/process.lua:359: in function <...sch/.local/share/nvim/lazy/neogit/lua/neogit/process.lua:325>
2000 function: 0x01018192a0 ...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...ch/.local/share/nvim/lazy/neogit/lua/neogit/lib/json.lua:63: Failed to parse log json!: Expected value but found invalid token at character 22657
t\":\"dmy","wgMonthNames":["",<\>n"January","February","March",
stack traceback:
	[C]: in function 'error'
	...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: in function 'callback_or_next'
	...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:45: in function 'cb'
	...sch/.local/share/nvim/lazy/neogit/lua/neogit/process.lua:359: in function <...sch/.local/share/nvim/lazy/neogit/lua/neogit/process.lua:325>
	[C]: in function 'wait'
	...usch/.local/share/nvim/lazy/neogit/lua/neogit/status.lua:1477: in function 'after'
	.../.local/share/nvim/lazy/neogit/lua/neogit/lib/buffer.lua:494: in function <.../.local/share/nvim/lazy/neogit/lua/neogit/lib/buffer.lua:493>
	[C]: in function 'resume'
	...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:45: in function 'cb'
	...sch/.local/share/nvim/lazy/neogit/lua/neogit/process.lua:359: in function <...sch/.local/share/nvim/lazy/neogit/lua/neogit/process.lua:325>

Neovim version

NVIM v0.10.0-dev-2046+g9a2c98087-Homebrew
Build type: Release
LuaJIT 2.1.1703358377
Run "nvim -V1 -v" for more info

Operating system and version

macos 14.2.1 (23C71)

Steps to reproduce

  1. nvim -nu minimal.lua
  2. :Neogit

Expected behavior

I expect the Neogit UI to be displayed

Actual behavior

A new tab is created but it is blank, and the above error message is displayed.

Minimal config

-- NOTE: See the end of this file if you are reporting an issue, etc. Ignore all the "scary" functions up top, those are
-- used for setup and other operations.
local M = {}

local base_root_path = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h") .. "/.min"
function M.root(path)
  return base_root_path .. "/" .. (path or "")
end

function M.load_plugin(plugin_name, plugin_url)
  local package_root = M.root("plugins/")
  local install_destination = package_root .. plugin_name
  vim.opt.runtimepath:append(install_destination)

  if not vim.loop.fs_stat(package_root) then
    vim.fn.mkdir(package_root, "p")
  end

  if not vim.loop.fs_stat(install_destination) then
    print(string.format("> Downloading plugin '%s' to '%s'", plugin_name, install_destination))
    vim.fn.system({
      "git",
      "clone",
      "--depth=1",
      plugin_url,
      install_destination,
    })
    if vim.v.shell_error > 0 then
      error(string.format("> Failed to clone plugin: '%s' in '%s'!", plugin_name, install_destination),
        vim.log.levels.ERROR)
    end
  end
end

---@alias PluginName string The plugin name, will be used as part of the git clone destination
---@alias PluginUrl string The git url at which a plugin is located, can be a path. See https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols for details
---@alias MinPlugins table<PluginName, PluginUrl>

---Do the initial setup. Downloads plugins, ensures the minimal init does not pollute the filesystem by keeping
---everything self contained to the CWD of the minimal init file. Run prior to running tests, reproducing issues, etc.
---@param plugins? table<PluginName, PluginUrl>
function M.setup(plugins)
  vim.opt.packpath = {}                      -- Empty the package path so we use only the plugins specified
  vim.opt.runtimepath:append(M.root(".min")) -- Ensure the runtime detects the root min dir

  -- Install required plugins
  if plugins ~= nil then
    for plugin_name, plugin_url in pairs(plugins) do
      M.load_plugin(plugin_name, plugin_url)
    end
  end

  vim.env.XDG_CONFIG_HOME = M.root("xdg/config")
  vim.env.XDG_DATA_HOME = M.root("xdg/data")
  vim.env.XDG_STATE_HOME = M.root("xdg/state")
  vim.env.XDG_CACHE_HOME = M.root("xdg/cache")

  -- NOTE: Cleanup the xdg cache on exit so new runs of the minimal init doesn't share any previous state, e.g. shada
  vim.api.nvim_create_autocmd("VimLeave", {
    callback = function()
      vim.fn.system({
        "rm",
        "-r",
        "-f",
        M.root("xdg")
      })
    end
  })
end

-- NOTE: If you have additional plugins you need to install to reproduce your issue, include them in the plugins
-- table within the setup call below.
M.setup({
  plenary = "https://github.com/nvim-lua/plenary.nvim.git",
  telescope = "https://github.com/nvim-telescope/telescope.nvim",
  diffview = "https://github.com/sindrets/diffview.nvim",
  neogit = "https://github.com/NeogitOrg/neogit"
})
-- WARN: Do all plugin setup, test runs, reproductions, etc. AFTER calling setup with a list of plugins!
-- Basically, do all that stuff AFTER this line.
require("neogit").setup({}) -- For instance, setup Neogit

Turns out it was happening only in a specific repository that had a commit with a message the neogit fails to parse. I've tracked it down to this commit: nushell/nushell@2e5a857

You're spot on, it's failing to parse a commit message. And... that's a hell of a commit message. If you're handy with parsing, I'd welcome the help there 😅 Otherwise.. might be a minute.

Yeah, it's a nasty one 😅 I'll see if I have a bit of time soon to have a look.

Seem to have the same problem. I'm not very proficient in Lua (yet), but I gather the json output from the cli.log would need to be sanitized in some way..
Great plugin!

I was able to reproduce the json parsing error with the following:

chore(api/scripts): Add dev script alias

## Summary

Some developers prefer using `dev` for their start command locally, so we're adding an alias from `dev` to `start`

## Test Plan

1. `turbo run build --filter=@snow/trpc --filter=opus-api-new-test-sept && pnpm run lint types && pnpm --filter=opus-api-new-test-sept run dev
`
2. `curl localhost:8787/status`
3. Verify output version:

```json
{"status":"ok","version":"1.1.1"}⏎

It seems like the carriage return character isn't being parsed:

...share/nvim/lazy/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...ue/.local/share/nvim/lazy/neogit/lua/neogit/lib/json.lua:63: Failed to parse log json!: Expected comma or array end
but found invalid token at character 153347
tus\":\"ok","version":"1.1.1"}<<e2>><8f><8e>\n```\n","ref_name":"","oid"

The carriage return character is encoded as <<e2>><8f><8e>

I'm assuming that's what's causing the issue?

Edit:
OP's post has this in the offending line: <\>

In case it helps debug, I've gotten the offending string, in my case, down to

{"":"","a":0}

This causes an error both in the commit subject and the body. I suspect this is the same case that @yousuf-haque is running into above. The resulting error is

...ck/packer/start/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...im/site/pack/packer/start/neogit/lua/neogit/lib/json.lua:63:
Failed to parse log json!: Expected comma or array end but found T_STRING at character 547
r","subject":"{\"\":\"","a":0}<">,"encoding":"","sanitized_subj
stack traceback:
[C]: in function 'error'
...ck/packer/start/plenary.nvim/lua/plenary/async/async.lua:18: in function 'callback_or_next'
...ck/packer/start/plenary.nvim/lua/plenary/async/async.lua:45: in function 'cb'
...vim/site/pack/packer/start/neogit/lua/neogit/process.lua:359: in function <...vim/site/pack/packer/start/neogit/lua/neogit/process.lua:325>

Seems like the string isn't being escaped correctly? I'll try debugging further when I get the chance.

Mind trying out this branch to see if it solves your issue? #1208

Mind trying out this branch to see if it solves your issue? #1208

Happy to test it out - where can I find a link to some docs on how to test this locally?

Do I simply clone the branch into my .lazy directory where plugins are downloaded + installed?

Apologies, I'm somewhat new to neovim/lazy

All good - for lazy, you can specify a "branch = " key where you define the neogit spec. Then :Lazy and sync :)

All good - for lazy, you can specify a "branch = " key where you define the neogit spec. Then :Lazy and sync :)

It works! The json is successfully parsed, and the tree is rendered as well as the commit detail view

Appreciate the quick turnaround :)

Haha, well the issue is 2months old, so I don't think I can call it quick, but regardless, you're welcome :) I'll merge it to master in a bit

Alright, fix is on master/nightly #1212 :)