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

Thread 'main' panicked at 'index out of bounds ...' #724

Closed
SunJukebox opened this issue Aug 10, 2022 · 9 comments
Closed

Thread 'main' panicked at 'index out of bounds ...' #724

SunJukebox opened this issue Aug 10, 2022 · 9 comments
Labels
bug Something isn't working

Comments

@SunJukebox
Copy link

Whenever I save a latex (.tex) file in neovim (stable, 0.7.2) with texlab running, the texlab instance crashes. The error message that it spits out when I set RUST_BACKTRACE=full is

[ERROR] .../vim/lsp/rpc.lua:420 "rpc" "texlab" "stderr" "thread 'main' panicked at 'index out of bounds: the len is 10 but the index is 10', src/line_index.rs:117:9\nstack backtrace:\n 0: 0x5570bf175944 - \n 1: 0x5570bf0459ec - \n 2: 0x5570bf171725 - \n 3: 0x5570bf1774ba - \n 4: 0x5570bf1771a9 - \n 5: 0x5570bf177b0a - \n 6: 0x5570bf1779e4 - \n 7: 0x5570bf175e74 - \n 8: 0x5570bf17774d - \n 9: 0x5570befb43e3 - \n 10: 0x5570befb4322 - \n 11: 0x5570bf214f81 - \n 12: 0x5570bf232ff7 - \n 13: 0x5570bf1ab8ab - \n 14: 0x5570bf2379f5 - \n 15: 0x5570bf0d81c0 - \n 16: 0x5570befcc7a3 - \n 17: 0x5570befd17dd - \n 18: 0x5570bf16a8ae - \n 19: 0x5570bf0d9062 - \n"
[ERROR] .../vim/lsp/rpc.lua:420 "rpc" "texlab" "stderr" " 20: 0x7f98b9b422d0 - \n 21: 0x7f98b9b4238a - __libc_start_main\n 22: 0x5570befcae05 - \n 23: 0x0 - \nthread '' panicked at 'called Result::unwrap() on an Err value: "SendError(..)"', /build/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/lsp-server-0.6.0/src/stdio.rs:29:37\nstack backtrace:\n "

For the sake of completeness, the source .tex file is

\documentclass{article}

\title{Test}

\begin{document}

\maketitle

\end{document}

However, when I run texlab -vvvv --log-file texlab.log instead of texlab, this error no longer appears; texlab runs without any hitches. I have no clue as to why this is the case. Thank you for any help you can offer.

@SunJukebox SunJukebox changed the title Thread 'main' panicked at 'index out of bounds: the len is (num. lines in .tex file) but the index is (num. lines in .tex file)', src/line_index.rs:117:9 Thread 'main' panicked at 'index out of bounds ... Aug 10, 2022
@SunJukebox SunJukebox changed the title Thread 'main' panicked at 'index out of bounds ... Thread 'main' panicked at 'index out of bounds ...' Aug 10, 2022
@clason
Copy link
Contributor

clason commented Aug 10, 2022

can you share your Neovim configuration for texlab?

@SunJukebox
Copy link
Author

cmd = { "texlab" },
settings = {
  texlab = {
    build = { onSave = true },
      forwardSearch = {
        executable = "zathura",
        args = { "--synctex-forward", "%l:1:%f", "%p" },
      },
    },
  },
}

@clason
Copy link
Contributor

clason commented Aug 10, 2022

and what's your texlab version?

@clason
Copy link
Contributor

clason commented Aug 10, 2022

try specifying the full set of build arguments (see documentation)

@SunJukebox
Copy link
Author

I am running version 4.2.1 . Thank you for the suggestion. I just tried with

build = {
          executable = 'latexmk',
          args = { '-pdf', '-interaction=nonstopmode', '-synctex=1', '%f' },
          onSave = false,
          forwardSearchAfter = false,
},

(keeping everything else the same), and I still received the same error.

@pfoerster
Copy link
Member

Thanks for the report!

This problem is likely not caused by the build feature. Instead, texlab likely receives another textDocument/* request, which causes a lookup in the LineIndex so that the server can map line/column UTF-16 positions to UTF-8 offsets, which are used internally. Afterwards, the UTF-8 offsets are converted back to the LSP representation.

@SunJukebox
Does the example document include a final newline? The 10 in the panic message is the line number.

@SunJukebox
Copy link
Author

Thanks for the detailed reply. There should be a final newline in the example that I did not add. Also, I want to add that, after downgrading texlab to v. 4.1.0, I no longer have this issue.

@pfoerster
Copy link
Member

I think I have found the issue. Can you try out #730, please? The currently released version wrongly reloads the TeX file after saving, even if it still open in the editor. This can result in a text synchronization issue.

@pfoerster pfoerster added the bug Something isn't working label Aug 16, 2022
@SunJukebox
Copy link
Author

Thank you @pfoerster for your help. Using texlab compiled from the issue-724 branch fixed the issue.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Sep 9, 2022
## [4.2.2] - 28.08.2022

### Fixed

- Do not watch the same directory multiple times, which can result in a memory leak on Windows ([#737](latex-lsp/texlab#679))
- Fix detection of root document when sharing files between projects ([#679](latex-lsp/texlab#679))
- Fix text synchronization problem caused by file watcher ([#724](latex-lsp/texlab#724))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants