[vim/vim] serverlist() fails when there is no connection to the X server (PR #21124)

thinca (Vim Github Repository) <[email protected]>
Newsgroups gmane.editors.vim.devel
Message-ID <vim/vim/pull/[email protected]>
## Problem

Since patch 9.2.0818 (#20716), `serverlist()` gives `E240: No connection to the X server` when the X11 clientserver backend cannot connect to the X server — for example on a Wayland-only system or with `$DISPLAY` unset. Before that patch it returned an empty result.

## Why this is a regression

- **It contradicts the documentation.** `:help serverlist()` says *"When there are no servers or the information is not available an empty string is returned"*, and 9.2.0818 did not update it.
- **The error was deliberately removed before.** Patch 6.0.191: *"When no servers are available serverlist() gives an error instead of returning an empty string"* → *"Don't give an error message"*. Patch 6.1.349 did the same for `--serverlist` when the display cannot be opened.
- **Entry points and backends now disagree.** In exactly the situation where the function fails, the `--serverlist` command line argument still prints an empty list, and the socket backend still returns an empty list.
- **The return type is broken on the failing path.** `rettv` is never set, so the result is a Number rather than a String or a List:
  ```vim
  silent! let r = serverlist()
  echo type(r)   " 0 (Number), r == 0
  ```

## Solution

Do not give an error when the X server cannot be reached; return an empty string, or an empty `List` when the `"list"` option is used.

The `"list"` option now always results in a `List` when no server names are available. That is the type inconsistency 9.2.0818 set out to fix — `serverlist({'list': 1})` returning a String — and it is fixed for every backend, including a build without `+clientserver`.

## Tests

`Test_clientserver_serverlist_without_x11()` now checks that a child Vim without `$DISPLAY` returns `''` from `serverlist()` and `[]` from `serverlist(#{list: v:true})`. It fails before the fix and passes after it:

```
# before
Found errors in Test_clientserver_serverlist_without_x11():
... line 36: Expected 0 but got 1
# after
Executed 1 test
```

The child process wraps the calls in a try/catch because an error in a sourced script only aborts the failing command: without it the assertion is never reached, `v:errors` stays empty and the test passes even when `serverlist()` fails (verified: exit code 0).

The `catch /E240:/` workaround that 9.2.0818 added to `Test_remote_serverlist()` in `test_vim9_builtin.vim` is no longer needed and is removed, so that test checks the return types again.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/21124

-- Commit Summary --

  * serverlist() fails when there is no connection to the X server

-- File Changes --

    M runtime/doc/builtin.txt (3)
    M src/clientserver.c (17)
    M src/testdir/test_clientserver.vim (18)
    M src/testdir/test_vim9_builtin.vim (12)

-- Patch Links --

https://github.com/vim/vim/pull/21124.patch
https://github.com/vim/vim/pull/21124.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/vim/vim/pull/21124
You are receiving this because you are subscribed to this thread.

Message ID: <vim/vim/pull/[email protected]>

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/vim/vim/pull/21124%40github.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.