feat: don't always report update errors to frontend

This commit is contained in:
James Houlahan
2021-01-14 16:07:33 +01:00
parent 10301b8600
commit 9bb7c828cd
4 changed files with 43 additions and 6 deletions

View File

@ -31,6 +31,7 @@ import (
"github.com/ProtonMail/proton-bridge/internal/imap"
"github.com/ProtonMail/proton-bridge/internal/smtp"
"github.com/ProtonMail/proton-bridge/internal/updater"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
@ -165,8 +166,13 @@ func checkAndHandleUpdate(u types.Updater, f frontend.Frontend, autoUpdate bool)
}
if err := u.InstallUpdate(version); err != nil {
logrus.WithError(err).Error("An error occurred while silent installing updates")
if errors.Cause(err) == updater.ErrDownloadVerify {
logrus.WithError(err).Warning("Skipping update installation due to temporary error")
} else {
logrus.WithError(err).Error("The update couldn't be installed")
f.NotifySilentUpdateError(err)
}
return
}

View File

@ -29,6 +29,7 @@ import (
"github.com/ProtonMail/proton-bridge/internal/frontend/types"
"github.com/ProtonMail/proton-bridge/internal/importexport"
"github.com/ProtonMail/proton-bridge/internal/updater"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
@ -113,8 +114,13 @@ func checkAndHandleUpdate(u types.Updater, f frontend.Frontend, autoUpdate bool)
}
if err := u.InstallUpdate(version); err != nil {
logrus.WithError(err).Error("An error occurred while silent installing updates")
if errors.Cause(err) == updater.ErrDownloadVerify {
logrus.WithError(err).Warning("Skipping update installation due to temporary error")
} else {
logrus.WithError(err).Error("The update couldn't be installed")
f.NotifySilentUpdateError(err)
}
return
}

View File

@ -0,0 +1,25 @@
// Copyright (c) 2021 Proton Technologies AG
//
// This file is part of ProtonMail Bridge.
//
// ProtonMail Bridge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ProtonMail Bridge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
package updater
import "errors"
var (
ErrDownloadVerify = errors.New("failed to download or verify the update")
ErrInstall = errors.New("failed to install the update")
)

View File

@ -142,11 +142,11 @@ func (u *Updater) InstallUpdate(update VersionInfo) error {
r, err := client.DownloadAndVerify(update.Package, update.Package+".sig", u.kr)
if err != nil {
return errors.Wrap(err, "failed to download and verify update package")
return errors.Wrap(ErrDownloadVerify, err.Error())
}
if err := u.installer.InstallUpdate(update.Version, r); err != nil {
return errors.Wrap(err, "failed to install update package")
return errors.Wrap(ErrInstall, err.Error())
}
u.curVer = update.Version