Provide a friendlier error when an update fails (#8228)

Add upgrading documentation as well
This commit is contained in:
Harshavardhana
2019-09-12 13:03:42 -07:00
committed by kannappanr
parent 73e4e99942
commit 9fa727d154
2 changed files with 29 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ import (
"context"
"crypto"
"encoding/hex"
"errors"
"fmt"
"io/ioutil"
"net"
@@ -521,10 +522,19 @@ func doUpdate(updateURL, sha256Hex, mode string) (err error) {
Checksum: sha256Sum,
},
); err != nil {
if os.IsPermission(err) {
if rerr := update.RollbackError(err); rerr != nil {
return AdminError{
Code: AdminUpdateApplyFailure,
Message: err.Error(),
Message: fmt.Sprintf("Failed to rollback from bad update: %v", rerr),
StatusCode: http.StatusInternalServerError,
}
}
var pathErr *os.PathError
if errors.As(err, &pathErr) {
return AdminError{
Code: AdminUpdateApplyFailure,
Message: fmt.Sprintf("Unable to update the binary at %s: %v",
filepath.Dir(pathErr.Path), pathErr.Err),
StatusCode: http.StatusForbidden,
}
}