mirror of
https://github.com/restic/restic.git
synced 2026-06-21 08:04:18 +00:00
selfupdate: improve error handling
This commit is contained in:
@@ -80,9 +80,12 @@ func extractToFile(buf []byte, filename, target string, printf func(string, ...i
|
||||
return err
|
||||
}
|
||||
if err = newFile.Sync(); err != nil {
|
||||
_ = newFile.Close()
|
||||
_ = os.Remove(newFile.Name())
|
||||
return err
|
||||
}
|
||||
if err = newFile.Close(); err != nil {
|
||||
_ = os.Remove(newFile.Name())
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ func GitHubLatestRelease(ctx context.Context, owner, repo string) (Release, erro
|
||||
var msg githubError
|
||||
jerr := json.NewDecoder(res.Body).Decode(&msg)
|
||||
if jerr == nil {
|
||||
_ = res.Body.Close()
|
||||
return Release{}, fmt.Errorf("unexpected status %v (%v) returned, message:\n %v", res.StatusCode, res.Status, msg.Message)
|
||||
}
|
||||
}
|
||||
@@ -137,6 +138,7 @@ func getGithubData(ctx context.Context, url string) ([]byte, error) {
|
||||
}
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
_ = res.Body.Close()
|
||||
return nil, fmt.Errorf("unexpected status %v (%v) returned", res.StatusCode, res.Status)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user