Skip to content

error handling not compatible with libdbus ABI #1

@smcv

Description

@smcv

When a libdbus function with a DBusError * parameter fails (returning whatever out-of-range value indicates error, usually NULL or FALSE), it must set the error indicator. A user of libdbus is allowed to assume the error has been set after a failing call. For instance, this is valid:

DBusError error = DBUS_ERROR_INIT;
DBusConnection *connection;

connection = dbus_bus_get (..., &error);

if (!connection)
  {
    fprintf (stderr, "Warning: unable to connect to bus: %s: %s\n", error.name, error.message);

    if (strcmp (error.name, "... some more specific error ...") == 0)
      fprintf (stderr, "Maybe install dbus-x11 and try again?\n");

    dbus_error_free (&error);
  }

With nobus, that would crash in the fprintf call on platforms where you can't printf NULL through %s (which works as an extension in glibc but isn't allowed in ISO C), or in the strcmp call.

A DBusError is a struct that can be allocated on the stack and contains two public strings, the machine-readable name and the human-readable message, plus some extra members that nobus can safely ignore. It would be reasonable for nobus to set the error.name to "org.freedesktop.DBus.Error.Failed" or "org.freedesktop.DBus.Error.NotSupported" for all failable functions, with some message mentioning nobus in error.message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions