emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.79k stars 889 forks source link

LSP server download swallows errors #3802

Open Rconybea opened 2 years ago

Rconybea commented 2 years ago

Thank you for the bug report

Bug description

If host cannot run language server (bad config / can't run executable), errors may be swallowed instead of being reported to lsp-log.

Background:

  1. setting up lsp (lsp-mode-20221104.1904) with emacs 28.0.50
  2. host VM a fairly old+stable linux, I think its RHEL 7. uname reports as 3.10.0-1160.71.1.el7.x86_64
  3. I don't have root privileges, need to take contents of /lib, /lib64, /usr/lib etc as given

with minimal lsp install:

(use-package lsp-mode :ensure t)
(add-hook 'c++-mode-hook #'lsp)

Attempting M-x lsp would loop forever:

  1. emacs asks to download a language server;
  2. user responds clangd:
  3. emacs proceeds to print a few progress messages (contacting github.com:443 ...)
  4. downloaded clangd appears in ~/.emacs.d/.cache/lsp/clangd_13.0.0/bin/clangd
  5. ... repeat forever

Note that the lsp-log

Steps to reproduce

  1. supply bad value for lsp-clients-clangd-args:

(setq lsp-clients-clangd-args "--header-insertion-decorators=0") ;; <--- should have been a list

  1. Invoke M-x lsp in a .cpp buffer

Expected behavior

error on modeline or *lsp-log*: Wrong type argument: listp, "--header-insertion-decorators=0" or unable to execute: /path/to/clangd, error: ...

Which Language Server did you use?

lsp-clangd

OS

Linux

Error callstack

(nothing here)

Anything else?

I believe the error-swallowing code is here (from lsp_mode.el):

(defun lsp--server-binary-present? (client)
  (unless (equal (lsp--client-server-id client) 'lsp-pwsh)
    (condition-case ()
      (-some-> client lsp--client-new-connection (plist-get :test?) funcall)
     (error nil)
     (args out-of-range nil))))

In my case the original problem was triggered by downloaded clangd failing to run because it expects libc.so.6 to have symbol GLIBC_2.18. After I managed to diagnose this, tried fixing the config by pointing at different clangd executable (for example on my host /usr/bin/clangd runs without incident). Unfortunately I'd produced a malformed config with

(setq lsp-clients-clangd-args "--header-insertion-decorators=0 --log=verbose") ;; BROKEN

which causes the same infinite-loop symptom.

Can demonstrate with elisp in scratch buffer like:

(require 'lsp)               ;; establishes lsp-clients variable
(require 'lsp-clangd) ;; populates (gethash 'clangd lsp-clients)

(setq myclient (gethash 'clangd lsp-clients))
(lsp--server-binary-present? myclient)  --> nil ;; silent failure - no error on modeline, no *lsp-log*

if problem caused by bad config, then maybe:

(-some-> client lsp--client-new-connection (plist-get :test?) funcall) 

without enclosing condition-case gives useful error like "do-seq: Wrong type argument: listp, ..." however afaict if problem caused by not being able to run clangd executable at all, I don't see error being reported anywhere.

Suggest it would be helpful to:

  1. create *lsp-log* earlier, before attempting (lsp--server-binary-present?)
  2. progress message, something like "checking for clangd binary"
  3. report any errors caught in (lsp--server-binary-present?) to *lsp-log*
josteink commented 1 year ago

I'm experiencing a similar issue on latest Ubuntu LTS, wrt to installing clangd.

It fails to install, and then when it has failed, it tries again and repeats and repeats until aborted.

jostein@dev-jostein:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:    22.04
Codename:   jammy

I'm seeing the following error in emacs when lsp-mode tries to install clangd:

The argument 'Expand-Archive' is not recognized as the name of a script file. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Usage: pwsh[.exe] [-Login] [[-File] <filePath> [args]]
                  [-Command { - | <script-block> [-args <arg-array>]
                                | <string> [<CommandParameters>] } ]
                  [-ConfigurationName <string>] [-ConfigurationFile <filePath>]
                  [-CustomPipeName <string>] [-EncodedCommand <Base64EncodedCommand>]
                  [-ExecutionPolicy <ExecutionPolicy>] [-InputFormat {Text | XML}]
                  [-Interactive] [-MTA] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile]
                  [-NoProfileLoadTime] [-OutputFormat {Text | XML}] 
                  [-SettingsFile <filePath>] [-SSHServerMode] [-STA] 
                  [-Version] [-WindowStyle <style>] 
                  [-WorkingDirectory <directoryPath>]

       pwsh[.exe] -h | -Help | -? | /?

PowerShell Online Help https://aka.ms/powershell-docs

All parameters are case-insensitive.

Checking Expand-Archive interactively in powershell, it works:

jostein@dev-jostein:~$ powershell --version
PowerShell 7.3.0
jostein@dev-jostein:~$ pwsh
PowerShell 7.3.0
PS /home/jostein> Expand-Archive

cmdlet Expand-Archive at command pipeline position 1
Supply values for the following parameters:
Path: 

So even if we are using PowerShell, this should work.

But... uh why is PowerShell preferred over plain, native unzip when on Linux? I do have unzip installed! Honestly! :smile:

jostein@dev-jostein:~$ which unzip
/usr/bin/unzip