Skip to content
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

Misleading error when dune not in PATH: -32600: no document found with uri #1417

Open
t-gebauer opened this issue Dec 9, 2024 · 0 comments

Comments

@t-gebauer
Copy link

t-gebauer commented Dec 9, 2024

It just took me way too long to figure out why ocaml-lsp did not work correctly when adding dune-project and dune files to my repository. Highlighting partially was off (No semantic highlighting?)
And on document hover it returned the following, confusing error message:

ocamllsp: -32600: no document found with uri: file:///home/user/projects/ocaml-lsp-test-project/hello/bin/main.ml

`:LspLog`
[ERROR][2024-12-09 22:09:52] .../vim/lsp/rpc.lua:770	"rpc"	"/etc/neovim-nix-dependencies/bin/ocamllsp"	"stderr"	'Uncaught error when handling notification:\n{\n  "params": {\n    "textDocument": {\n      "version": 115,\n      "uri": "file:///home/user/projects/ocaml-lsp-test-project/hello/bin/main.ml"\n    },\n    "contentChanges": [\n      {\n        "rangeLength": 1,\n        "range": {\n          "end": { "character": 0, "line": 108 },\n          "start": { "character": 38, "line": 107 }\n        },\n        "text": "\\nlet () = print_endline \\"Hello, World!\\"\\n"\n      }\n    ]\n  },\n  "method": "textDocument/didChange",\n  "jsonrpc": "2.0"\n}\nError:\n[ { exn =\n      "jsonrpc response error {\\n\\\n      \\  \\"code\\": -32600,\\n\\\n      \\  \\"message\\": \\"no document found with uri: file:///home/user/projects/ocaml-lsp-test-project/hello/bin/main.ml\\"\\n\\\n       }"\n  ; backtrace =\n      "Raised at Jsonrpc.Response.Error.raise in file \\"jsonrpc/src/jsonrpc.ml\\", line 186, characters 18-29\\n\\\n       Called from Ocaml_lsp_server__Document_store.change_document in file \\"ocaml-lsp-server/src/document_store.ml\\", line 132, characters 12-22\\n\\\n       Called from Ocaml_lsp_server.on_notification in file \\"ocaml-lsp-server/src/ocaml_lsp_server.ml\\", lines 743-744, characters 6-62\\n\\\n       Called from Lsp_fiber__Rpc.Server.h_on_notification.(fun) in file \\"lsp-fiber/src/rpc.ml\\", line 413, characters 23-52\\n\\\n       Called from Fiber__Scheduler.exec in file \\"fiber/src/scheduler.ml\\", line 73, characters 8-11\\n\\\n       "\n  }\n]\n'

This was surprising, because earlier, without the dune configuration files, both worked fine.

Apparently ocaml-lsp needs to invoke dune. This was not obvious. Especially, because ocaml-lsp was successfully talking to my dune build -w process, and displaying its errors!

Later i found the real error hidden somewhere earlier in the logs:

jsonrpc response error { \"code\": -32603, \"message\": \"dune binary not found\ " }"

`:LspLog`
1332 [START][2024-12-09 22:01:10] LSP logging initiated
1333 [ERROR][2024-12-09 22:01:10] .../vim/lsp/rpc.lua:770  "rpc" "/etc/neovim-nix-dependencies/bin/ocamllsp" "stderr"  "Uncaught error when      handling notification:\n"
1334 [ERROR][2024-12-09 22:01:10] .../vim/lsp/rpc.lua:770  "rpc" "/etc/neovim-nix-dependencies/bin/ocamllsp" "stderr"  '{\n  "params": {\n         "textDocument": {\n      "version": 0,\n      "uri": "file:///home/user/projects/ocaml-lsp-test-project/hello/bin/main.ml",\n      "     languageId": "ocaml",\n      "text": "let () = print_endline \\"Hello, World!\\"\\n"\n    }\n  },\n  "method": "textDocument/didOpen",\     n  "jsonrpc": "2.0"\n}\nError:\n[ { exn =\n      "jsonrpc response error { \\"code\\": -32603, \\"message\\": \\"dune binary not found\     \" }"\n  ; backtrace =\n      "Raised at Jsonrpc.Response.Error.raise in file \\"jsonrpc/src/jsonrpc.ml\\", line 186, characters 18-29\     \n\\\n       Called from Ocaml_lsp_server__Merlin_config.get_process in file \\"ocaml-lsp-server/src/merlin_config.ml\\", line 160, cha     racters 19-37\\n\\\n       Called from Ocaml_lsp_server__Merlin_config.config in file \\"ocaml-lsp-server/src/merlin_config.ml\\", line                                                                                                                                            

Solution: Add dune to the ocaml-lps's PATH


Maybe:

  • always return the real error: "dune binary not found", instead of "no document found with uri"?
  • add a note to the Readme, that "dune needs to be in the PATH" when working with dune projects?

Or do nothing, others can now find this issue when searching for the misleading error message ;)


nixos-24.11
NVIM v0.10.2
ocamllsp 1.19.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant