Improve pause info display and error handling
This commit is contained in:
@@ -89,11 +89,11 @@ func (c *Control) resume() (retErr error) {
|
||||
defer c.locker.Unlock()
|
||||
|
||||
defer func() {
|
||||
// update states after resume attempt
|
||||
c.updateStatesAndNotify()
|
||||
// log error if resume failed
|
||||
if retErr != nil {
|
||||
c.mgr.Error("Failed to resume: " + retErr.Error())
|
||||
c.updateStatesAndNotifyError("Resume operation failed", retErr)
|
||||
c.mgr.Error("Error occurred while resuming: " + retErr.Error())
|
||||
} else {
|
||||
c.updateStatesAndNotify()
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -228,3 +228,26 @@ func (c *Control) updateStatesAndNotify() {
|
||||
notifications.Notify(c.pauseNotification)
|
||||
c.pauseNotification.SyncWithState(c.states)
|
||||
}
|
||||
|
||||
// updateStatesAndNotifyError updates the paused states and sends an error notification.
|
||||
// No thread safety, caller must hold c.locker.
|
||||
func (c *Control) updateStatesAndNotifyError(errDescription string, err error) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if errDescription == "" {
|
||||
errDescription = "Error"
|
||||
}
|
||||
|
||||
// Error notification
|
||||
c.pauseNotification = ¬ifications.Notification{
|
||||
EventID: "control:error",
|
||||
Type: notifications.Error,
|
||||
Title: errDescription,
|
||||
Message: err.Error(),
|
||||
EventData: &c.pauseInfo,
|
||||
}
|
||||
notifications.Notify(c.pauseNotification)
|
||||
c.pauseNotification.SyncWithState(c.states)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user