Skip to content

Commit 1a76661

Browse files
milan-zededaOhmSpectator
authored andcommitted
Fix Bearer ConnectionError type
Bearer's ConnectionError is represented in ModemManager DBus API as a list of two fields: DBus Error Name and Error message. The method for retreiveing this propery expects generic list []interface{}, which will have length 2 and contain 2 strings. See: https://www.freedesktop.org/software/ModemManager/doc/latest/ModemManager/gdbus-org.freedesktop.ModemManager1.Bearer.html#gdbus-property-org-freedesktop-ModemManager1-Bearer.ConnectionError This commit fixes the previous code which assumed that struct with the two strings is returned. Signed-off-by: Milan Lenco <[email protected]>
1 parent 1beeddf commit 1a76661

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pkg/wwan/mmagent/mmdbus/client.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -777,17 +777,18 @@ func (c *Client) getBearerStatus(bearerObj dbus.BusObject) (bearer types.WwanBea
777777
bearer.ConnectedAt = uint64(time.Now().Unix()) - uint64(value)
778778
}
779779
}
780-
connectionError := struct {
781-
DBusErrName string
782-
ErrMessage string
783-
}{}
780+
781+
var connectionError []interface{}
784782
_ = getDBusProperty(c, bearerObj, BearerPropertyConnectionError, &connectionError)
785-
if connectionError.DBusErrName != "" {
786-
if connectionError.ErrMessage != "" {
787-
bearer.ConnectionError = connectionError.DBusErrName + ": " +
788-
connectionError.ErrMessage
789-
} else {
790-
bearer.ConnectionError = connectionError.DBusErrName
783+
if len(connectionError) == 2 {
784+
dbusErrName, ok1 := connectionError[0].(string)
785+
errMessage, ok2 := connectionError[1].(string)
786+
if ok1 && ok2 && dbusErrName != "" {
787+
if errMessage != "" {
788+
bearer.ConnectionError = dbusErrName + ": " + errMessage
789+
} else {
790+
bearer.ConnectionError = dbusErrName
791+
}
791792
}
792793
}
793794
var bearerProperties map[string]dbus.Variant

0 commit comments

Comments
 (0)