polarmutex/beancount-language-server

"thread 'main' panicked at 'called `Result::unwrap()` on an `Err`

Closed this issue · 8 comments

When using the LSP in neovim, I often get the following error, and need to close and reopen my ledger file..

[ERROR][2022-12-18 12:11:43] .../vim/lsp/rpc.lua:734	"rpc"	"beancount-language-server"	"stderr"	"thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Char range out of bounds: char range 382023..382023, Rope/RopeSlice char length 382019', /Users/duartecarmo/.cargo/registry/src/github.com-1ecc6299db9ec823/ropey-1.5.0/src/rope.rs:546:37\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n"

Thanks for a great project!!!

@duarteocarmo does this prevent the LSP from attaching to the buffer as well?

When I run LspInfo I see that "beancount matched the file type" but "0 clients attached to this buffer"

When I check LspLog I see the same error as you.

Just want to confirm that this error is preventing all use for you as well, right?

Yup. It attaches for a bit, then something goes wrong. And then I need to close and open back again the file

Hm, mine looks immediate and 100% of the time. I open a beancount file, it shows as not attached, and the only error in the log is what you're reporting. I assume it's the same thing. Reopening doesn't really help.

Thanks for confirming

Can you post your config? Something to check, right now you have to pass the root beancount filet to the LSP. Here in the near future I want to change this to default to the file opened if no file is configured

When I first posted this, all I had done was installed via mason and added to local servers here:
https://github.com/thusspokecolton/nvim/blob/main/lua/user/lsp/mason.lua

After seeing your comment, I tried adding a beancount.lua
https://github.com/thusspokecolton/nvim/blob/main/lua/user/beancount.lua

I did try to debug it a bit by following the debug steps listed in the below repo (that's when I found the error that duarteocarmo reported)
https://github.com/neovim/nvim-lspconfig#debugging

I get the same results even with the beancount.lua (shown below). I also tried specifying in my plugins.lua to use the commit
from the last release just as another test.

// output of LspInfo

Detected filetype:   beancount
0 client(s) attached to this buffer: 
Other clients that match the filetype: beancount
Config: beancount
 filetypes:         beancount, bean
 root directory:    /Users/.../projects/beans
 cmd:               beancount-language-server --stdio
 cmd is executable: true
 autostart:         true
 custom handlers:   

// output of LspLog

[START][2022-12-23 19:48:22] LSP logging initiated
[ERROR][2022-12-23 19:48:22] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error(\"missing field `journal_file`\", line: 0, column: 0)', /Users/crivelli/.cargo/registry/src/github.com-1ecc6299db9ec823/beancount-language-server-1.2.5/src/server.rs:71:42\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n"

iwfan commented

Same here, but I had set the environment variable RUST_BACKTRACE to the "full":

[START][2023-01-03 23:20:56] LSP logging initiated
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ()', /Users/f/.asdf/installs/rust/1.66.0/registry/src/github.com-1ecc6299db9ec823/beancount-language-server-1.2.5/src/server.rs:81:96\nstack backtrace:\n"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"   0:        0x102964162 - std::backtrace_rs::backtrace::libunwind::trace::h74d17ea919046bae\n                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5\n   1:        0x102964162 - std::backtrace_rs::backtrace::trace_unsynchronized::h2fc77fd5a14165ac\n                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5\n   2:        0x102964162 - std::sys_common::backtrace::_print_fmt::h2687aa7717781133\n                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/sys_common/backtrace.rs:65:5\n   3:        0x102964162 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hdc69a6f447628e71\n                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/sys_common/backtrace.rs:44:22\n"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"   4:        0x102981eea - core::fmt::write::hb9e764fa47ae8444\n           "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"                    at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/fmt/mod.rs:1209:17\n   5:        0x10296095c - std::io::"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"Write::write_fmt::h8fc98987ed860a54\n                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/io/mod.rs:1682:15\n"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"   6:        0x102963f2a - std::sys_common::backtrace::_print::h882e8250b822b8b0\n               "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"                at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/sys_common/backtrace.rs:47:5\n   7:        0x102963f2a - std::sys_common::backtrace::print::h488fe4c0b1fb9d50\n                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/sys_common/backtrace.rs:34:9\n   8:        0x102965816 - std::panicking::default_hook::{{closure}}::h5618ea3156b8b833\n                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:267:22\n"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"   9:        0x102965567 - std::panicking::default_hook::h0421c26a8a92801c\n                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:286:9\n"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"  10:        0x102965f5d - std::panicking::rust_panic_with_hook::h57383cd32463c250\n "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"                              at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:688:13\n  11:     "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"   0x102965d13 - std::panicking::begin_panic_handler::{{closure}}::h1d1f7305cfe67fdd\n                  "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"             at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:579:13\n  12:        0x1029645f8 - std::sys_common::backtrace::__rust_end_short_backtrace::hd8e12e82ff026bae\n "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"                              at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/sys_common/backtrace.rs:137:18\n  13:        0x1029659dd - rust_begin_unwind\n                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:575:5\n"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"  14:        0x1029a2e13 - core::panicking::panic_fmt::h7894cd1015cfee41\n                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/panicking.rs:65"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	":14\n  15:        0x1029a30d5 - core::result::unwrap_failed::h3077b600131e58d4\n        "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"                       at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/result.rs:1791:5\n  16:        0x1026ea605 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"h08418ccf0cae7522\n  17:        0x102703649 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hef20f3db761f274b\n  18"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	":        0x10271d2ea - <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll::h89e87568193456b9\n  19:      "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"  0x1026b3c0e - <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll::ha11c7264e1179052\n"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"  20:        0x1026ef980 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"::poll::h375e0900d6185698\n  21:        0x10274944d - <futures_util::future::either::Either<A,"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"B> as core::future::future::Future>::poll::h9265dd0fcae50346\n  22:      "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"  0x1026ef075 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h35153141e5f45273"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"\n  23:        0x102782966 - <core::pin::Pin<P> as core::future::future::"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"Future>::poll::h0f0aab5e979f9654\n  24:        0x1026f8125 - <core::future::from_generator::GenFuture<T"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"> as core::future::future::Future>::poll::ha617c74bf2c6d6e4\n  25:        0x10271acd7 - <futures_util::"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"future::future::map::Map<Fut,F> as core::future::future::Future>::poll::h13464c81457fdb4f\n  "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"26:        0x1026c8b6b - futures_util::stream::stream::StreamExt::poll_next_unpin::h538c441d9ae91909\n  27:      "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"  0x10274cb12 - <futures_util::stream::stream::buffer_unordered::BufferUnordered<St> as futures_core::stream::Stream>::poll_next::h6b9e7792c1beba98\n"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"  28:        0x1026c84fb - <futures_util::stream::stream::filter_map::FilterMap<St,Fut,F> as futures_core::"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"stream::Stream>::poll_next::ha9b4f608030f9a51\n  29:        0x1026c81bc - <futures_util::stream::stream::forward::Forward<St,Si,Item> as core::future::future::Future>::poll::he3a47d41971c06fc\n  30:        0x10271b4b1 - <futures_util::future::future::map::Map<Fut,F> as"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	" core::future::future::Future>::poll::h34dee815c67e80f5\n  31:        0x1026b36a6 - <futures_util::future::poll_fn::PollFn<F> as core::future::future::Future>::poll::"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"h2c3b502e17b9c4da\n  32:        0x10270245b - <core::future::from_generator::GenFuture<T> as core::future::future::Future>"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"::poll::he52c2efcb298e1c9\n  33:        0x1026919e6 - tokio::park::thread::CachedParkThread::block_on::he0536da52c8bea99\n"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"  34:        0x1027454eb - tokio::runtime::thread_pool::ThreadPool::block_on::head38703fc6b27ea\n  35:     "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"   0x102691adb - tokio::runtime::Runtime::block_on::h52512f327a893ceb\n  36:    "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"    0x102790d78 - beancount_language_server::main::h0527d16afe6afb91\n  37:        0x1026d14c6 - std::sys_common::backtrace::__rust_begin_short_backtrace::h1e2a4f10f425324b"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"\n  38:        0x10273b19c - std::rt::lang_start::{{closure}}::ha9c4ad40b4e22031\n"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"  39:        0x10295b604 - core::ops::function::impls::<impl core::ops::function::FnOnce<"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"A> for &F>::call_once::h61195f273fbb2744\n                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/ops/function.rs:286:13\n  40:        0x10295b604 - std::panicking::try::"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"do_call::h742c41daae50fa78\n                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:483:40\n  41:        0x10295b604 - std::panicking::try::h289fd06090f9252d\n"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:447:19\n"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"  42:        0x10295b604 - std::panic::catch_unwind::h442e40ac2db064f5\n            "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"                   at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panic.rs:137:14\n  43:        0x10295b604 - std::rt::"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"lang_start_internal::{{closure}}::haebd6112c3b7ec52\n                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/rt.rs:148:48"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"\n  44:        0x10295b604 - std::panicking::try::do_call::h5621965127b9aadb\n                "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:483:40\n  45:        0x10295b604 - std::panicking::try::h55c66b03bc020b32\n"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:447:19\n  46:        0x10295b604 - std::panic::catch_unwind::hf00d6becf2cfdae2\n   "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"                            at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panic.rs:137:14\n  47:        0x10295b604 - std::rt::"
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"lang_start_internal::h9ca2efac34d80f78\n                               at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/rt.rs:148:20\n  "
[ERROR][2023-01-03 23:20:56] .../vim/lsp/rpc.lua:733	"rpc"	"beancount-language-server"	"stderr"	"48:        0x102790e5c - _main\n  49:     0x7ff80bfaf310 - <unknown>\n"

lsp version: 1.2.5
cargo 1.66.0 (d65d197ad 2022-11-15)

I am in the middle of a refactor to switch from tower-lsp to lsp-server then I am going to change the root file behavior to default to the current file if not present so it won't crash on start

Thanks for the great work @polarmutex

let me know if you need some testers