Skip to content

Commit ceb95d9

Browse files
corneliusweigk8s-ci-robot
authored andcommitted
Improve error messages when installing from manifest+archive (#361)
* Improve error messages when installing from manifest+archive * Improve error message when opening a local archive fails
1 parent 613ee9b commit ceb95d9

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

pkg/download/downloader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func NewDownloader(v Verifier, f Fetcher) Downloader {
209209
func (d Downloader) Get(uri, dst string) error {
210210
body, size, err := download(uri, d.verifier, d.fetcher)
211211
if err != nil {
212-
return errors.Wrapf(err, "failed to get the uri %q", uri)
212+
return err
213213
}
214214
return extractArchive(dst, body, size)
215215
}

pkg/download/fetch.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type HTTPFetcher struct{}
3737
func (HTTPFetcher) Get(uri string) (io.ReadCloser, error) {
3838
resp, err := http.Get(uri)
3939
if err != nil {
40-
return nil, err
40+
return nil, errors.Wrapf(err, "failed to get the uri %q", uri)
4141
}
4242
return resp.Body, nil
4343
}
@@ -47,7 +47,8 @@ var _ Fetcher = fileFetcher{}
4747
type fileFetcher struct{ f string }
4848

4949
func (f fileFetcher) Get(_ string) (io.ReadCloser, error) {
50-
return os.Open(f.f)
50+
file, err := os.Open(f.f)
51+
return file, errors.Wrapf(err, "failed to open archive file %q for reading", f.f)
5152
}
5253

5354
// NewFileFetcher returns a local file reader.

pkg/installation/install.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func install(op installOperation, opts InstallOpts) error {
9595
// Download and extract
9696
glog.V(3).Infof("Creating download staging directory %q", op.downloadStagingDir)
9797
if err := os.MkdirAll(op.downloadStagingDir, 0755); err != nil {
98-
return errors.Wrapf(err, "could not create download path %q", op.downloadStagingDir)
98+
return errors.Wrapf(err, "could not create staging dir %q", op.downloadStagingDir)
9999
}
100100
defer func() {
101101
glog.V(3).Infof("Deleting the download staging directory %s", op.downloadStagingDir)
@@ -104,7 +104,7 @@ func install(op installOperation, opts InstallOpts) error {
104104
}
105105
}()
106106
if err := downloadAndExtract(op.downloadStagingDir, op.platform.URI, op.platform.Sha256, opts.ArchiveFileOverride); err != nil {
107-
return errors.Wrap(err, "failed to download and extract")
107+
return errors.Wrap(err, "failed to unpack into staging dir")
108108
}
109109

110110
applyDefaults(&op.platform)
@@ -146,7 +146,7 @@ func downloadAndExtract(extractDir, uri, sha256sum, overrideFile string) error {
146146

147147
verifier := download.NewSha256Verifier(sha256sum)
148148
err := download.NewDownloader(verifier, fetcher).Get(uri, extractDir)
149-
return errors.Wrap(err, "failed to download and verify file")
149+
return errors.Wrap(err, "failed to unpack the plugin archive")
150150
}
151151

152152
// Uninstall will uninstall a plugin.

0 commit comments

Comments
 (0)