kovidgoyal/kitty · error

failed to connect to system bus with error: %w

Error message

failed to connect to system bus with error: %w

What it means

show_settings calls dbus.SessionBus() and wraps its failure. Despite the message text saying 'system bus', the code actually connects to the session bus — the message is slightly misleading; the cause is a session bus connection failure.

Source

Thrown at kittens/desktop_ui/portal.go:277

func fetch_settings(conn *dbus.Conn, namespaces ...string) (ans ReadAllType, err error) {
	path := "/" + strings.ToLower(strings.ReplaceAll(DESKTOP_PORTAL_NAME, ".", "/"))
	obj := conn.Object(DESKTOP_PORTAL_NAME, dbus.ObjectPath(path))
	interface_name := strings.ReplaceAll(DESKTOP_PORTAL_NAME, "Desktop", "Settings")
	if len(namespaces) == 0 {
		namespaces = append(namespaces, "")
	}
	call := obj.Call(interface_name+".ReadAll", dbus.FlagNoAutoStart, namespaces)
	if err = call.Store(&ans); err != nil {
		return nil, fmt.Errorf("Failed to read response from ReadAll with error: %w", err)
	}
	return
}

func show_settings(opts *ShowSettingsOptions) (err error) {
	conn, err := dbus.SessionBus()
	if err != nil {
		return fmt.Errorf("failed to connect to system bus with error: %w", err)
	}
	defer conn.Close()
	var response ReadAllType
	response, err = fetch_settings(conn, opts.InNamespace...)
	if opts.AsJson {
		unwrapped := make(map[string]map[string]any, len(response))
		for ns, m := range response {
			w := make(map[string]any, len(m))
			for k, a := range m {
				w[k] = a.Value()
			}
			unwrapped[ns] = w
		}
		j, err := json.MarshalIndent(unwrapped, "", "  ")
		if err != nil {
			return fmt.Errorf("Failed to format the response as JSON: %w", err)
		}
		fmt.Println(string(j))

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Set/verify DBUS_SESSION_BUS_ADDRESS and confirm the socket exists
  2. Start a session bus with dbus-run-session or dbus-launch for non-graphical use
  3. Share the host session bus socket into containers
Defensive patterns

Strategy: validation

Validate before calling

if os.Getenv("DBUS_SESSION_BUS_ADDRESS") == "" {
    return errors.New("run inside a graphical session or set DBUS_SESSION_BUS_ADDRESS")
}

Try / catch

conn, err := dbus.SessionBus()
if err != nil {
    // skip settings features; environment has no session bus
}

Prevention

When it happens

Trigger: Running `kitten desktop-ui show-settings` in an environment where the D-Bus session bus is unavailable or DBUS_SESSION_BUS_ADDRESS is unset/invalid.

Common situations: SSH sessions, containers, cron jobs, or minimal environments without a running session bus.

Related errors


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/1760d15b2161042a. Report an issue: GitHub.