blahgeek / emacs-lsp-booster

Emacs LSP performance booster
MIT License
468 stars 15 forks source link

The error is not clear when failed to run the lsp server as a child process #28

Closed zino23 closed 4 days ago

zino23 commented 6 days ago
# gopls should not be in $PATH
cargo run -- gopls                                                                                                                                                                                                                             

If something bad happens during running the lsp server, e.g. the lsp server is not in $PATH, the backtrace looks like this:

[2024-11-27T12:18:36Z INFO  emacs_lsp_booster::app] Running server "gopls"
[2024-11-27T12:18:36Z INFO  emacs_lsp_booster::app] Will convert server json to bytecode! bytecode options: BytecodeOptions { object_type: Plist, null_value: Nil, false_value: Nil }
Error: No such file or directory (os error 2)

Stack backtrace:
   0: std::backtrace_rs::backtrace::libunwind::trace
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1: std::backtrace_rs::backtrace::trace_unsynchronized
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2: std::backtrace::Backtrace::create
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/backtrace.rs:331:13
   3: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
   4: emacs_lsp_booster::app::run_app_forever
   5: emacs_lsp_booster::main
   6: std::sys_common::backtrace::__rust_begin_short_backtrace
   7: std::rt::lang_start::{{closure}}
   8: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:284:13
   9: std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
  10: std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
  11: std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
  12: std::rt::lang_start_internal::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:48
  13: std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
  14: std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
  15: std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
  16: std::rt::lang_start_internal
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:20
  17: _main

It isn't obvious what went wrong, and we don't even know which line in emacs_lsp_booster::app::run_app_forever specifically is the culprit.

The fix is easy. Simply attach a context with <anyhow::Result as anyhow::Context>::with_context method.

Afterwards, the error looks like this:

[2024-11-27T12:29:25Z INFO  emacs_lsp_booster::app] About to run the lsp server with command "gopls"
[2024-11-27T12:29:25Z INFO  emacs_lsp_booster::app] Will convert server json to bytecode! bytecode options: BytecodeOptions { object_type: Plist, null_value: Nil, false_value: Nil }
Error: Failed to run the lsp server with command: "gopls"

Caused by:
    No such file or directory (os error 2)

Stack backtrace:
   0: std::backtrace_rs::backtrace::libunwind::trace
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1: std::backtrace_rs::backtrace::trace_unsynchronized
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2: std::backtrace::Backtrace::create
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/backtrace.rs:331:13
   3: <E as anyhow::context::ext::StdError>::ext_context
             at /Users/zino/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anyhow-1.0.78/src/context.rs:27:29
   4: anyhow::context::<impl anyhow::Context<T,E> for core::result::Result<T,E>>::with_context
             at /Users/zino/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anyhow-1.0.78/src/context.rs:65:31
   5: emacs_lsp_booster::app::run_app_forever
             at ./src/app.rs:110:20
   6: emacs_lsp_booster::main
             at ./src/main.rs:76:23
   7: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
   8: std::sys_common::backtrace::__rust_begin_short_backtrace
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys_common/backtrace.rs:155:18
   9: std::rt::lang_start::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:166:18
  10: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:284:13
  11: std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
  12: std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
  13: std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
  14: std::rt::lang_start_internal::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:48
  15: std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
  16: std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
  17: std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
  18: std::rt::lang_start_internal
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:20
  19: std::rt::lang_start
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:165:17
  20: _main

By the way, do you use a .rustfmt.toml locally? The code is not formatted by rustfmt, so when I save the file and the auto-formatting tool is run, the changes are all over the place. Just my opinion that if the code is correctly formatted, it will be easier for others to contribute to this project :). Do you mind formatting the code or accepting a PR that does the formatting? I am ok to create such a PR :).

Thx for your great project!

blahgeek commented 4 days ago

Thanks for your report and PR.

By the way, do you use a .rustfmt.toml locally? The code is not formatted by rustfmt, so when I save the file and the auto-formatting tool is run, the changes are all over the place. Just my opinion that if the code is correctly formatted, it will be easier for others to contribute to this project :). Do you mind formatting the code or accepting a PR that does the formatting? I am ok to create such a PR :).

Thanks you for your offer. No I didn't use rustfmt locally. Personally I'm not a big fan of enforced formatting rules. I believe that a programmer's formatting choice for some code (indention etc.) may contain info about the codes' structure or logic. Also, this repo is relatively small regarding both repo size and number of contributors anyway. So I would like to keep it as it for now. :)

zino23 commented 2 days ago

Thanks for your reply. As someone often annoyed by Go's dogmatic code formatting, I totally understand your choice :).