harpoon icon indicating copy to clipboard operation
harpoon copied to clipboard

Error when running Harpoon commands

Open unclewalter opened this issue 1 year ago • 22 comments

Heya! I'm having an odd issue where I get this error whenever I run a Harpoon command. I'm running Harpoon2 and it was working fine and then one day, I opened up neovim and it was not fine. I don't know what has changed, but whenever I try and run it I get this error:

E5108: Error executing lua: ...nvim/site/pack/packer/start/harpoon/lua/harpoon/data.lua:98: Harpoo
n: there was an error reading the data file, cannot read data
stack traceback:
        [C]: in function 'error'
        ...nvim/site/pack/packer/start/harpoon/lua/harpoon/data.lua:98: in function 'data'
        ...nvim/site/pack/packer/start/harpoon/lua/harpoon/init.lua:61: in function 'list'
        /Users/kevanatkins/.config/nvim/after/plugin/harpoon.lua:7: in function </Users/kevanatkin
s/.config/nvim/after/plugin/harpoon.lua:7>

I've got some keymaps set up here: harpoon.lua And installed from here: packer.lua

Maybe I've done something stupid in my configuration, a bug or mercury is in retrograde.

unclewalter avatar Dec 19 '23 15:12 unclewalter

Your config looks good to me, so this likely needs some debugging. Mind sharing harpoon's logger output? Also, does the data file exist / has it been created? It should be located at $XDG_DATA_HOME/nvim/harpoon.json.

willothy avatar Dec 21 '23 06:12 willothy

Strange, neither the log file has been written nor has a data file. I do see other log files in there, but not Harpoon's. Also I'm running on Mac OS 13.2.1 (22D68).

unclewalter avatar Dec 21 '23 07:12 unclewalter

Strange, neither the log file has been written nor has a data file. I do see other log files in there, but not Harpoon's.

Ah sorry I should've mentioned this, harpoon doesn't actually write to a file - just use require("harpoon").logger:show() and paste the output :)

willothy avatar Dec 21 '23 07:12 willothy

Hmm. It seems to be just giving me empty output when I run it.

unclewalter avatar Dec 21 '23 07:12 unclewalter

Hmm. It seems to be just giving me empty output when I run it.

Alright, no worries.

A few ideas:

  • Do you have plenary.nvim installed?
  • What version of nvim are you using?
  • Does the output of vim.fn.stdpath("data") have a trailing slash?
  • Try manually creating harpoon.json in the data dir, and see if that works (?)

Other than that I don't have a mac to test on so likely will have to wait for prime or someone else on this one, but given where the error is happening I would guess that it's some platform-specific filesystem quirk that's causing the issue.

Unfortunately harpoon doesn't really log the actual error at the moment, so there's not much way to get more detailed info on this without modifying the plugin. If you're open to it you could modify your local clone of harpoon and add some vim.prints to read_data in data.lua.

willothy avatar Dec 21 '23 08:12 willothy

Do you have plenary.nvim installed?

  • Yep! What version of nvim are you using?
  • v0.9.2 Does the output of vim.fn.stdpath("data") have a trailing slash?
  • No trailing slash Try manually creating harpoon.json in the data dir, and see if that works (?)
  • Turns out I was incorrect before, the data file is there, I look in the wrong spot. Still getting the error, though.

unclewalter avatar Dec 21 '23 08:12 unclewalter

Thanks! If you cat the file, does it look like valid json? Can jq parse it (if you have jq installed)?

Not that jq is used, just wondering if the file could've been corrupted somehow causing vim.json.decode to fail.

willothy avatar Dec 21 '23 08:12 willothy

Just ran jq and I got "jq: parse error: Invalid numeric literal at line 1, column 764"

Here's a cat of harpoon.json:

{"projects": {"/Users/kevanatkins": {"mark": {"marks": []}, "term": {"cmds": []}}, "/Users/kevanatkins/Developer/NTH_brightsign": {"mark": {"marks": [{"col": 51, "row": 105, "filename": "info-view/src/index.js"}]}, "term": {"cmds": []}}, "/Users/kevanatkins/Developer/OSC-send": {"mark": {"marks": [{"col": 29, "row": 13, "filename": "main.go"}, {"col": 3, "row": 3, "filename": "go.mod"}]}, "term": {"cmds": []}}, "/Users/kevanatkins/.config/nvim": {"mark": {"marks": []}, "term": {"cmds": []}}}, "global_settings": {"tabline_suffix": "   ", "save_on_toggle": false, "tabline": false, "excluded_filetypes": ["harpoon"], "save_on_change": true, "enter_on_sendcmd": false, "tabline_prefix": "   ", "mark_branch": false, "tmux_autoclose_windows": false}}mark_branch": false, "tabline": false, "excluded_filetypes": ["harpoon"], "tabline_prefix": "   ", "tabline_suffix": "   ", "enter_on_sendcmd": false, "save_on_change": true, "tmux_autoclose_windows": false}}%

unclewalter avatar Dec 21 '23 08:12 unclewalter

That % at the end is definitely not valid json. Looking at the schema, it looks like it's from the old harpoon (but also has that invalid char at the end)... I think you should try moving the file and allowing harpoon to recreate it.

willothy avatar Dec 21 '23 09:12 willothy

That fixed it! Deleting harpoon.json got it working again. Seems strange that % would appear. I'll keep an eye on it and see if it does something like that again.

Thank you for your help!

unclewalter avatar Dec 21 '23 09:12 unclewalter

That fixed it! Deleting harpoon.json got it working again. Seems strange that % would appear. I'll keep an eye on it and see if it does something like that again.

Awesome, glad that worked!

willothy avatar Dec 21 '23 09:12 willothy

I’m glad too. My temporary Harpoonless existence was most cold and dark.

unclewalter avatar Dec 21 '23 09:12 unclewalter

That % at the end is definitely not valid json. Looking at the schema, it looks like it's from the old harpoon (but also has that invalid char at the end)... I think you should try moving the file and allowing harpoon to recreate it.

Thanks, exact same issue appeared to me after i ran packer sync today.

TheIbraDev avatar Dec 22 '23 13:12 TheIbraDev

Thanks, exact same issue appeared to me after i ran packer sync today.

Are you saying that the harpoon schema gets a trailing percentage to it every time you update your plugins? Because I've never had that happen to me, and that seems like a very big issue.

theKnightsOfRohan avatar Dec 23 '23 02:12 theKnightsOfRohan

Are you saying that the harpoon schema gets a trailing percentage to it every time you update your plugins? Because I've never had that happen to me, and that seems like a very big issue.

That does seem like a very serious issue, not sure what could be causing it though. @Rossvold had you previously been using harpoon v1 / did the issue appear right when you upgraded?

willothy avatar Dec 23 '23 05:12 willothy

Thanks, exact same issue appeared to me after i ran packer sync today.

Are you saying that the harpoon schema gets a trailing percentage to it every time you update your plugins? Because I've never had that happen to me, and that seems like a very big issue.

Are you saying that the harpoon schema gets a trailing percentage to it every time you update your plugins? Because I've never had that happen to me, and that seems like a very big issue.

That does seem like a very serious issue, not sure what could be causing it though. @Rossvold had you previously been using harpoon v1 / did the issue appear right when you upgraded?

I migrated from old harpoon to harpoon2, used it for a couple of days, then when i ran packerSync it suddenly threw an error which lead me to this issue. Not sure what's going on, updating is not messing with the json for now.

TheIbraDev avatar Dec 24 '23 03:12 TheIbraDev

I had this same problem when upgrading and deleting the harpoon.json files fixed it. Thank ya'll!

SeanAtSigma2 avatar Dec 28 '23 17:12 SeanAtSigma2

Thanks! Always great when these threads lead to such a clean solution

catasaurus avatar Jan 01 '24 00:01 catasaurus

Ran into the same issue, but instead of a % it just had some very weird json structure in there.

laytan avatar Feb 03 '24 21:02 laytan

That % at the end is definitely not valid json.

That % is an indicator that there is no newline at the end of the file. The problem is actually malformed JSON.

cwinkler avatar Feb 19 '24 09:02 cwinkler

Thanks for that! I thought it could be an incompatibility with folke/noice.nvim because that started exactly when I installed it :sweat_smile: But deleting the data file worked.

Had to look a bit for the path of the data file in linux, found it by running this in neovim command line: :lua =vim.fn.stdpath('data') (for me it was ~/.local/share/nvim/harpoon.json)

d-gubert avatar Mar 08 '24 14:03 d-gubert

Opening the harpoon.json (~/.local/share/nvim/harpoon.json) showed the issue immediately for me... malformed json. replaced the contents with {} and harpoon is running happily again.

anisjonischkeit avatar Mar 25 '24 01:03 anisjonischkeit