Improve pause info display and error handling

This commit is contained in:
Alexandr Stelnykovych
2025-11-26 13:01:24 +02:00
parent 4913147dd5
commit d635db77c2
4 changed files with 51 additions and 16 deletions

View File

@@ -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 = &notifications.Notification{
EventID: "control:error",
Type: notifications.Error,
Title: errDescription,
Message: err.Error(),
EventData: &c.pauseInfo,
}
notifications.Notify(c.pauseNotification)
c.pauseNotification.SyncWithState(c.states)
}