kovidgoyal/kitty · error
could not connect to session D-Bus: %s
Error message
could not connect to session D-Bus: %s
What it means
Portal.Start fails when dbus.SessionBus() cannot connect to the user's session bus (DBUS_SESSION_BUS_ADDRESS). The message wraps the underlying connection error.
Source
Thrown at kittens/desktop_ui/portal.go:185
Properties: properties,
Signals: signals,
}
interfaces := []introspect.Interface{
introspect.IntrospectData, interface_data,
}
if len(properties) > 0 {
interfaces = append(interfaces, prop.IntrospectData)
}
n := &introspect.Node{Name: object_path, Interfaces: interfaces}
if err = conn.Export(introspect.NewIntrospectable(n), op, introspect.IntrospectData.Name); err != nil {
return fmt.Errorf("failed to export introspected methods with error: %w", err)
}
return
}
func (self *Portal) Start() (err error) {
if self.bus, err = dbus.SessionBus(); err != nil {
return fmt.Errorf("could not connect to session D-Bus: %s", err)
}
reply, err := self.bus.RequestName(PORTAL_BUS_NAME, dbus.NameFlagDoNotQueue)
if err != nil {
return fmt.Errorf("failed to register dbus name: %v", err)
}
if reply != dbus.RequestNameReplyPrimaryOwner {
return fmt.Errorf("can't register D-Bus name: name already taken")
}
props := PropSpec{
"version": {Value: uint32(1), Writable: false, Emit: prop.EmitFalse},
}
signals := SignalSpec{
"SettingChanged": {{"namespace", "s"}, {"key", "s"}, {"value", "v"}},
}
methods := MethodSpec{
"Read": {{"namespace", "s", false}, {"key", "s", false}, {"value", "v", true}},
"ReadAll": {{"namespaces", "as", false}, {"value", "a{sa{sv}}", true}},
}View on GitHub (pinned to 6d5d0c4406)
Solutions
- Verify DBUS_SESSION_BUS_ADDRESS is set (echo $DBUS_SESSION_BUS_ADDRESS) and points to a live socket
- Launch a session bus (dbus-launch, eval $(dbus-launch)) or use dbus-run-session
- In containers/SSH, forward or share the host session bus socket
- Use dbus-monitor or busctl --user to confirm the bus responds
Defensive patterns
Strategy: validation
Validate before calling
if os.Getenv("DBUS_SESSION_BUS_ADDRESS") == "" {
return errors.New("no session bus; set DBUS_SESSION_BUS_ADDRESS")
} Try / catch
if _, err := dbus.SessionBus(); err != nil {
// degrade gracefully: disable desktop-ui features
} Prevention
- Probe for a session bus before launching the kitten server
- Use dbus-run-session in headless test environments
When it happens
Trigger: Running the desktop-ui kitten server in an environment without a session bus: SSH sessions without bus address forwarding, containers, cron jobs, or minimal Wayland/X setups.
Common situations: Missing or invalid DBUS_SESSION_BUS_ADDRESS env var; running inside a container or non-graphical session; ssh -X without dbus forwarding.
Related errors
- failed to connect to system bus with error: %w
- failed to register dbus name: %v
- failed to export interface: %s at object path: %s with error
- failed to export properties with error: %w
- failed to export introspected methods with error: %w
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/2b7a6f38787e8ea7.
Report an issue: GitHub.