Send the last error for disconnected networks in network status

This adds support for sending the exact error message of a network when
it is disconnected, in the reply to the service command `network
status`. This lets users easily examine why a network is currently
disconnected.

No lock is needed because all reads and writes of network.lastError are
made in the user goroutine.

Closes: https://todo.sr.ht/~emersion/soju/28
This commit is contained in:
delthas 2020-04-04 04:51:48 +02:00 committed by Simon Ser
parent eb941d2d2b
commit 8c11205ee6
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -208,6 +208,9 @@ func handleServiceNetworkStatus(dc *downstreamConn, params []string) error {
details = fmt.Sprintf("%v channels", len(uc.channels)) details = fmt.Sprintf("%v channels", len(uc.channels))
} else { } else {
statuses = append(statuses, "disconnected") statuses = append(statuses, "disconnected")
if net.lastError != nil {
details = net.lastError.Error()
}
} }
if net == dc.network { if net == dc.network {