Subject: Emacs 29.1: (x-open-connection (getenv "DISPLAY")) gets "Display :0.0 does not exist" error

From: Herman <[email-masked]>
Date: Mon, 4 Dec 2023 19:31:38 +0200

Hi !

'x-create-frame' succeeds, but 'x-open-connection' fails with same display argument.

This error "Display :0.0 does not exist" happens only, when variable 'debug-on-error' is non-nil. When 'debug-on-error' is nil, the error is not present. I.e. it works on the principle - you get what you are looking for.

Tested also on Emacs 28.2 and there error is not present regardless of the value of the variable 'debug-on-error'.

xfwm4 4.18.0
xorg-server 21.1.9
Emacs 29.1
Archlinux

How to reproduce:
#################

$ emacs --fg-daemon -Q
...
Starting Emacs daemon.
$ emacsclient --eval "(setq debug-on-error t)"
t
$ emacsclient --eval "(x-open-connection (getenv \"DISPLAY\"))"
nil
...
Debugger entered--Lisp error: (error "Display :0.0 does not exist")
  signal(error ("Display :0.0 does not exist"))
  error("Display %s does not exist" ":0.0")
  get-device-terminal(":0.0")
  frames-on-display-list(":0.0")
  font-setting-change-default-font(":0.0" nil)
  dynamic-setting-handle-config-changed-event((config-changed-event font-render ":0.0"))
  funcall-interactively(dynamic-setting-handle-config-changed-event (config-changed-event font-render ":0.0"))
  call-interactively(dynamic-setting-handle-config-changed-event nil [(config-changed-event font-render ":0.0")])
  command-execute(dynamic-setting-handle-config-changed-event nil [(config-changed-event font-render ":0.0")] t)

The full testing:
#################

$ emacs --fg-daemon -Q
...
Starting Emacs daemon.
$ emacsclient --eval "(setq debug-on-error t)"
t
$ emacsclient --eval "debug-ignored-errors"
(beginning-of-line beginning-of-buffer end-of-line end-of-buffer end-of-file buffer-read-only file-supersession mark-inactive user-error)
$ emacsclient --eval "debug-on-signal"
nil
$ emacsclient --eval "debug-on-event"
sigusr2
$ emacsclient --eval "(terminal-list)"
(#<terminal 0 on initial_terminal>)
$ emacsclient --eval "(get-device-terminal nil)"
#<terminal 0 on initial_terminal>
$ emacsclient --eval "(x-display-list)"
nil
$ emacsclient --eval "(x-open-connection (getenv \"DISPLAY\"))"
nil
...
Debugger entered--Lisp error: (error "Display :0.0 does not exist")
  signal(error ("Display :0.0 does not exist"))
  error("Display %s does not exist" ":0.0")
  get-device-terminal(":0.0")
  frames-on-display-list(":0.0")
  font-setting-change-default-font(":0.0" nil)
  dynamic-setting-handle-config-changed-event((config-changed-event font-render ":0.0"))
  funcall-interactively(dynamic-setting-handle-config-changed-event (config-changed-event font-render ":0.0"))
  call-interactively(dynamic-setting-handle-config-changed-event nil [(config-changed-event font-render ":0.0")])
  command-execute(dynamic-setting-handle-config-changed-event nil [(config-changed-event font-render ":0.0")] t)

$ emacs --fg-daemon -Q
...
Starting Emacs daemon.
$ emacsclient --eval "(setq debug-on-error t)"
t
$ emacsclient --eval "(x-create-frame \`((display . ,(getenv \"DISPLAY\"))))"
#<frame *scratch* - GNU Emacs at Elitebook 0x55f5f31eeba0>
$ emacsclient --eval "(terminal-list)"
(#<terminal 0 on initial_terminal> #<terminal 1 on :0.0>)
$ emacsclient --eval "(get-device-terminal nil)"
#<terminal 1 on :0.0>
$ emacsclient --eval "(x-display-list)"
(":0.0")
$ emacsclient --eval "(kill-emacs)"
$ emacs --fg-daemon -Q
...
Starting Emacs daemon.
$ emacsclient --eval "(x-open-connection (getenv \"DISPLAY\"))"
nil
$ emacsclient --eval "(x-display-list)"
(":0.0")
$ emacsclient --eval "(terminal-list)"
(#<terminal 0 on initial_terminal> #<terminal 1 on :0.0>)
$ emacsclient --eval "(get-device-terminal nil)"
#<terminal 0 on initial_terminal>