blahgeek / emacs-lsp-booster

Emacs LSP performance booster
MIT License
418 stars 12 forks source link

Failing with dbt #22

Open egh opened 4 months ago

egh commented 4 months ago

Hi,

I'm trying this out with https://github.com/fivetran/dbt-language-server but I'm getting the following error. If I disable emacs-lsp-booster things work fine. Let me know what info I can provide. Thanks!

[2024-05-24T22:40:24Z INFO  emacs_lsp_booster::app] Running server "dbt-language-server" "--stdio"
[2024-05-24T22:40:24Z INFO  emacs_lsp_booster::app] Will convert server json to bytecode! bytecode options: BytecodeOptions { object_type: Plist, null_value: Nil, false_value: Nil }
thread '<unnamed>' panicked at /github/workspace/src/app.rs:145:18:
called `Result::unwrap()` on an `Err` value: Server->client read thread failed

Caused by:
    Invalid header format

Stack backtrace:
   0: anyhow::error::<impl anyhow::Error>::msg
   1: emacs_lsp_booster::rpcio::rpc_read
   2: emacs_lsp_booster::app::process_server_reader
   3: std::sys_common::backtrace::__rust_begin_short_backtrace
   4: core::ops::function::FnOnce::call_once{{vtable.shim}}
   5: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
   6: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
   7: std::sys::unix::thread::Thread::new::thread_start
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys/unix/thread.rs:108:17
stack backtrace:
   0:     0x77cfe055b8ec - std::backtrace_rs::backtrace::libunwind::trace::h370587616c149a45
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x77cfe055b8ec - std::backtrace_rs::backtrace::trace_unsynchronized::h4cc55038e4a874cd
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x77cfe055b8ec - std::sys_common::backtrace::_print_fmt::hc26cc3c2eddc21d7
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x77cfe055b8ec - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb67f6e94152691e9
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x77cfe059a0fc - core::fmt::rt::Argument::fmt::h1fd35fc4c88687b8
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/rt.rs:138:9
   5:     0x77cfe059a0fc - core::fmt::write::h738793984be7f52c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/mod.rs:1094:21
   6:     0x77cfe055910e - std::io::Write::write_fmt::h84056616c47209ca
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/io/mod.rs:1714:15
   7:     0x77cfe055b6d4 - std::sys_common::backtrace::_print::h20a11f09f8216cd4
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x77cfe055b6d4 - std::sys_common::backtrace::print::h7b70e260a2475fa3
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x77cfe055d173 - std::panicking::default_hook::{{closure}}::h81c979645f368377
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:270:22
  10:     0x77cfe055ce8c - std::panicking::default_hook::h157ab9bf73bc8932
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:290:9
  11:     0x77cfe04b60fe - emacs_lsp_booster::main::{{closure}}::hb2b0baf668103ab3
  12:     0x77cfe055d86e - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hd2597171485cc473
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2021:9
  13:     0x77cfe055d86e - std::panicking::rust_panic_with_hook::hec9e488e5d9ea17f
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:711:13
  14:     0x77cfe055d5f7 - std::panicking::begin_panic_handler::{{closure}}::h83232311f2354a3d
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:599:13
  15:     0x77cfe055be16 - std::sys_common::backtrace::__rust_end_short_backtrace::h8a82556d18c9cf5a
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x77cfe055d342 - rust_begin_unwind
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:595:5
  17:     0x77cfe04a05d3 - core::panicking::panic_fmt::h9fb1cf80aef8bb8a
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:67:14
  18:     0x77cfe04a099a - core::result::unwrap_failed::hdeffda1fd287c7d3
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/result.rs:1652:5
  19:     0x77cfe04a717e - std::sys_common::backtrace::__rust_begin_short_backtrace::h056dc2d0ff09f963
  20:     0x77cfe04c8767 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hd6158818be7a5cb0
  21:     0x77cfe0561af5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc4b69460ab0b58b3
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
  22:     0x77cfe0561af5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hff9ab78020349a37
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
  23:     0x77cfe0561af5 - std::sys::unix::thread::Thread::new::thread_start::h7fa77081a8285658
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys/unix/thread.rs:108:17

Process dbtls stderr finished
blahgeek commented 4 months ago

Hi,

Thanks for your report. Based on the error message, it seems that it received unexpected data from dbt-language-server (cannot parse as json-rpc header).

It would help a lot if you can post the output of the language server here. You may do it in this way:

  1. Add a new dbt-language-server-wrapper.sh script in your $PATH (and remember to make it executable), with the following content:
#!/bin/bash
exec dbt-language-server "$@" < <(tee -a /tmp/dbt.stdin.txt) > >(tee -a /tmp/dbt.stdout.txt)
  1. Change your emacs config to use dbt-language-server-wrapper.sh instead of dbt-language-server
  2. Reproduce the issue with emacs-lsp-booster. Then you should find the input and output data to/from the language server in /tmp/dbt.stdin.txt and /tmp/dbt.stdout.txt respectively.

(I tried to reproduce this locally but unfortunately cannot get dbt-language-server working (constantly getting an "invalid_type" type error...).. )

egh commented 4 months ago

Thanks @blahgeek ! Here is my emacs setup for dbt:

https://github.com/fivetran/dbt-language-server/issues/1426#issuecomment-2130470832

I can send you those files, but they contain some semi-private information. Can I email you? My email is on my profile.

blahgeek commented 4 months ago

I can now successfully run dbt-language-server based on your configuration, without any issues you mentioned :)

image

So I think I need your input/output contents to debug. I sent you an email.

blahgeek commented 4 months ago

Hi @egh ,

At the end of your dbt.output.txt there are the following lines:

{"jsonrpc":"2.0","id":3,"result":[]}Running server on localhost:40109...
Server listening on localhost:40109

These "Running server on ..." lines are the ones that causes the issue. The dbt language server should not output these contents to stdout according to lsp spec (it should only contains "Content-Length: xxx" followed by json objects).

So I think maybe you should report to dbt-language-server project about this bug. (Though as I said, I personally cannot reproduce this, so I'm not sure why or when it happens)

On the other hand, emacs-lsp-booster could try to tolerate this kind of error and try to recover. I think that's how lsp-mode itself does, which explains why you don't have this issue without emacs-lsp-booster enabled. I will do this later.

egh commented 4 months ago

Hi @blahgeek ,

Thank you so much for looking into this! I will file an upstream bug.