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

Panicked on macOS Catalina when editing python code #1204

Closed
anzhi0708 opened this issue Nov 30, 2021 · 8 comments · Fixed by #2160
Closed

Panicked on macOS Catalina when editing python code #1204

anzhi0708 opened this issue Nov 30, 2021 · 8 comments · Fixed by #2160
Labels
A-helix-term Area: Helix term improvements A-language-server Area: Language server client C-bug Category: This is a bug

Comments

@anzhi0708
Copy link

anzhi0708 commented Nov 30, 2021

Hello, I guess helix just crashed in iTerm2 and I got this message

thread 'main' panicked at 'Failed to parse PublishDiagnostics params: Error { code: InvalidParams, message: "Invalid params: invalid value: integer `-1`, expected u32.", data: None }', helix-lsp/src/lib.rs:246:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I noticed that when pasting python code to helix running in iTerm2, iTerm2 warns you about tab size.
image

Paste the exact same code to Vim, no warnings at all.

And the code pasted into helix have messed up indent as well.

vim
image

hx
image

I know the code doesn't make sense, but the indent was twisted in helix.

The code was copied from a browser.
image

I was using python-lsp-server[full] and here's the output of pip3 list

Package             Version
------------------- ----------
astroid             2.9.0
attrs               21.2.0
autopep8            1.6.0
beniget             0.4.1
black               21.11b1
bleach              4.1.0
certifi             2021.10.8
charset-normalizer  2.0.7
click               8.0.3
Cython              0.29.24
defusedxml          0.7.1
Deprecated          1.2.13
entrypoints         0.3
flake8              4.0.1
Flask               2.0.2
frilouz             0.0.2
gast                0.5.3
idna                3.3
ipython-genutils    0.2.0
isort               5.10.1
itsdangerous        2.0.1
jedi                0.18.1
Jinja2              3.0.3
jsonschema          4.2.1
jupyter-client      7.1.0
jupyter-core        4.9.1
jupyterlab-pygments 0.1.2
lazy-object-proxy   1.6.0
MarkupSafe          2.0.1
mccabe              0.6.1
memestra            0.2.0
mistune             0.8.4
mypy                0.910
mypy-extensions     0.4.3
nbclient            0.5.9
nbconvert           6.3.0
nbformat            5.1.3
nest-asyncio        1.5.1
numpy               1.21.4
packaging           21.3
pandocfilters       1.5.0
parso               0.8.2
pathspec            0.9.0
pip                 21.3.1
platformdirs        2.4.0
pluggy              1.0.0
pycodestyle         2.8.0
pydocstyle          6.1.1
pyflakes            2.4.0
Pygments            2.10.0
pylint              2.12.1
pyls-flake8         0.4.0
pyls-isort          0.2.2
pyls-memestra       0.0.15
pylsp-mypy          0.5.2
pylsp-rope          0.1.7
pyparsing           3.0.6
pyrsistent          0.18.0
python-dateutil     2.8.2
python-lsp-black    1.0.0
python-lsp-jsonrpc  1.0.0
python-lsp-server   1.3.2
PyYAML              6.0
pyzmq               22.3.0
regex               2021.11.10
requests            2.26.0
rope                0.22.0
scipy               1.7.2
setuptools          59.0.1
six                 1.16.0
snowballstemmer     2.2.0
sqlmap              1.5.11
testpath            0.5.0
toml                0.10.2
tomli               1.2.2
torch               1.10.0
tornado             6.1
traitlets           5.1.1
typing_extensions   4.0.0
ujson               4.3.0
urllib3             1.26.7
webencodings        0.5.1
Werkzeug            2.0.2
wheel               0.37.0
wrapt               1.13.3
yapf                0.31.0
you-get             0.4.1555

Here's the log info in ~/.cache/helix/helix.log

2021-12-01T08:03:21.480 helix_term::application [WARN] lsp position out of bounds - Diagnostic { range: Range
{ start: Position { line: 5, character: 0 }, end: Position { line: 5, character: 1 } }, severity: Some(Warning
), code: Some(String("W391")), code_description: None, source: Some("flake8"), message: "blank line at end of
file", related_information: None, tags: None, data: None }
2021-12-01T08:04:05.343 helix_term::application [WARN] lsp position out of bounds - Diagnostic { range: Range
{ start: Position { line: 7, character: 6 }, end: Position { line: 7, character: 7 } }, severity: Some(Error),
 code: None, code_description: None, source: Some("mypy"), message: "invalid syntax", related_information: Non
e, tags: None, data: None }
2021-12-01T08:04:07.922 helix_term::application [WARN] lsp position out of bounds - Diagnostic { range: Range
{ start: Position { line: 7, character: 13 }, end: Position { line: 7, character: 23 } }, severity: Some(Error
), code: Some(String("E999")), code_description: None, source: Some("flake8"), message: "SyntaxError: invalid
syntax", related_information: None, tags: None, data: None }

...
2021-12-01T08:04:56.978 helix_term::application [WARN] lsp position out of bounds - Diagnostic { range: Range
{ start: Position { line: 8, character: 33 }, end: Position { line: 8, character: 37 } }, severity: Some(Error
), code: Some(String("E999")), code_description: None, source: Some("flake8"), message: "SyntaxError: invalid
syntax", related_information: None, tags: None, data: None }
2021-12-01T08:04:56.978 helix_term::application [WARN] lsp position out of bounds - Diagnostic { range: Range
{ start: Position { line: 8, character: 35 }, end: Position { line: 8, character: 39 } }, severity: Some(Error
), code: None, code_description: None, source: Some("mypy"), message: "invalid syntax", related_information: N
one, tags: None, data: None }
2021-12-01T08:04:58.411 helix_term::application [WARN] lsp position out of bounds - Diagnostic { range: Range
{ start: Position { line: 8, character: 34 }, end: Position { line: 8, character: 38 } }, severity: Some(Error
), code: Some(String("E999")), code_description: None, source: Some("flake8"), message: "IndentationError: exp
ected an indented block", related_information: None, tags: None, data: None }
2021-12-01T08:04:58.412 helix_term::application [WARN] lsp position out of bounds - Diagnostic { range: Range
{ start: Position { line: 8, character: 36 }, end: Position { line: 8, character: 37 } }, severity: Some(Error
), code: None, code_description: None, source: Some("mypy"), message: "expected an indented block", related_in
formation: None, tags: None, data: None }

uname -a:

Darwin Catalina.local 19.6.0 Darwin Kernel Version 19.6.0: Tue Oct 12 18:34:05 PDT 2021; root:xnu-6153.141.43~1/RELEASE_X86_64 x86_64

env | rg LC_CTYPE

LC_CTYPE=UTF-8

env | rg LC_TERMINAL

LC_TERMINAL_VERSION=3.4.13
LC_TERMINAL=iTerm2
@kirawi kirawi added A-language-server Area: Language server client C-bug Category: This is a bug labels Dec 1, 2021
@kirawi
Copy link
Member

kirawi commented Dec 1, 2021

For pasting, since you're using tabs I assume that you haven't changed the tab width via :indent-style? Is there a difference between pasting through the terminal and pasting through Helix (:clipboard-paste or space + p/P)?

@anzhi0708
Copy link
Author

For pasting, since you're using tabs I assume that you haven't changed the tab width via :indent-style?

No, I did't. There's no .toml file under my ~/.config/helix as well...

@anzhi0708
Copy link
Author

For pasting, since you're using tabs I assume that you haven't changed the tab width via :indent-style? Is there a difference between pasting through the terminal and pasting through Helix?

I copied the code directly into the terminal(not helix) and the warning about tab size showed up again.
image

@kirawi
Copy link
Member

kirawi commented Dec 1, 2021

Try pasting through Helix (:clipboard-paste-after or space + p/P)

@kirawi kirawi added the A-helix-term Area: Helix term improvements label Dec 1, 2021
@anzhi0708
Copy link
Author

Try pasting through Helix (:clipboard-paste-after or space + p/P)

:clipboard-paste-after did a perfect paste without indent error

@kirawi
Copy link
Member

kirawi commented Dec 1, 2021

Yeah, the terminal is messing it up by converting the indentation. Not sure how Vim avoids that.

@anzhi0708
Copy link
Author

Yeah, the terminal is messing it up by converting the indentation. Not sure how Vim avoids that.

I'll try to reproduce the crush in the beginning.
Thanks a lot for your help! :3

@the-mikedavis
Copy link
Member

I can reproduce this with ElixirLS by creating a file that fails to compile. The code looks roughly like:

Mox.defmock(MyMock, for: SomeModuleThatIsNotABehaviour)

The logger shows this message from the LS right before the crash:

{
  "jsonrpc": "2.0",
  "method": "textDocument/publishDiagnostics",
  "params": {
    "diagnostics": [
      {
        "message": "(ArgumentError) module SomeModuleThatIsNotABehaviour is not a behaviour, please pass a behaviour to :for\n\nStacktrace:\n  │ (mox 1.0.1) lib/mox.ex:365: Mox.validate_behaviour!/1\n  │ (mox 1.0.1) lib/mox.ex:383: anonymous fn/2 in Mox.generate_compile_time_dependency/1\n  │ (elixir 1.13.4) lib/enum.ex:2396: Enum.\"-reduce/3-lists^foldl/2-0-\"/3\n  │ (mox 1.0.1) lib/mox.ex:382: Mox.generate_compile_time_dependency/1\n  │ (mox 1.0.1) lib/mox.ex:349: Mox.defmock/2",
        "range": {
          "end": { "character": 0, "line": -1 },
          "start": { "character": 0, "line": -1 }
        },
        "severity": 1,
        "source": "Elixir"
      }
    ],
    "uri": "file:///home/michael/snip/snip/test/support/mocks.ex"
  }
}

And here's the full backtrace:

thread 'main' panicked at 'Failed to parse PublishDiagnostics params: Error { code: InvalidParams, message: "Invalid params: invalid value: integer `-1`, expected u32.", data: None }', helix-lsp/src/lib.rs:279:22
stack backtrace:
   0:     0x5607b669fbfc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3e2b509ce2ce6007
   1:     0x5607b5ff6c9c - core::fmt::write::h753c7571fa063ecb
   2:     0x5607b6697f95 - std::io::Write::write_fmt::h2815c0519c99ba09
   3:     0x5607b66a2da5 - std::panicking::default_hook::{{closure}}::h78d3e6cf97fc623d
   4:     0x5607b66a2a23 - std::panicking::default_hook::hda898f8d3ad1a5ae
   5:     0x5607b6563873 - helix_term::application::Application::run::{{closure}}::{{closure}}::h3dfe79fd2c65786a
   6:     0x5607b66a3451 - std::panicking::rust_panic_with_hook::h1a5ea2d6c23051aa
   7:     0x5607b66a311a - std::panicking::begin_panic_handler::{{closure}}::h07f549390938b73f
   8:     0x5607b66a0124 - std::sys_common::backtrace::__rust_end_short_backtrace::h5ec3758a92cfb00d
   9:     0x5607b66a2e7d - rust_begin_unwind
  10:     0x5607b5f7fd01 - core::panicking::panic_fmt::h3a79a6a99affe1d5
  11:     0x5607b5f7fdf3 - core::result::unwrap_failed::ha0327e3803285d6e
  12:     0x5607b61dc244 - helix_lsp::Notification::parse::h4b0c62c8102e9a30
  13:     0x5607b6571c02 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h0a7da9cc4c5b565a
  14:     0x5607b653db9e - tokio::park::thread::CachedParkThread::block_on::he36d1026cd6454bc
  15:     0x5607b65347e9 - tokio::runtime::thread_pool::ThreadPool::block_on::h27950ba51e21c469
  16:     0x5607b65526bc - tokio::runtime::Runtime::block_on::h0f21e182e7a55280
  17:     0x5607b653cfba - hx::main::h2020ee9f0a5b563f
  18:     0x5607b6534623 - std::sys_common::backtrace::__rust_begin_short_backtrace::h7c8e761f3c8b8510
  19:     0x5607b655245d - std::rt::lang_start::{{closure}}::hab23b0f9c2f1672d
  20:     0x5607b669f25e - std::rt::lang_start_internal::h52e73755f77c7dd9
  21:     0x5607b6540612 - main
  22:     0x7fba26b07790 - __libc_start_main
  23:     0x5607b5facf0a - _start
  24:                0x0 - <unknown>

That message from the language server is malformed: -1 is not a valid line.

We should be able to remove the panic in this block and replace it with an error log:

helix/helix-lsp/src/lib.rs

Lines 277 to 283 in 4b1fe36

let params: lsp::PublishDiagnosticsParams = params
.parse()
.expect("Failed to parse PublishDiagnostics params");
// TODO: need to loop over diagnostics and distinguish them by URI
Self::PublishDiagnostics(params)
}

Ultimately this is an upstream bug with ElixirLS though. It must not give -1 lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements A-language-server Area: Language server client C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants