Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(59)

Unified Diff: state/apiserver/client/client.go

Issue 59930043: Add errgo as a dep, and start using it.
Patch Set: Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: state/apiserver/client/client.go
=== modified file 'state/apiserver/client/client.go'
--- state/apiserver/client/client.go 2014-01-30 14:22:46 +0000
+++ state/apiserver/client/client.go 2014-02-03 14:31:54 +0000
@@ -9,6 +9,7 @@
"os"
"strings"
+ "github.com/errgo/errgo"
"github.com/loggo/loggo"
"launchpad.net/juju-core/charm"
@@ -851,47 +852,47 @@
store := config.AuthorizeCharmRepo(CharmStore, envConfig)
downloadedCharm, err := store.Get(charmURL)
if err != nil {
- return fmt.Errorf("cannot download charm %q: %v", charmURL.String(), err)
+ return errgo.Annotatef(err, "cannot download charm %q", charmURL.String())
}
// Open it and calculate the SHA256 hash.
downloadedBundle, ok := downloadedCharm.(*charm.Bundle)
if !ok {
- return fmt.Errorf("expected a charm archive, got %T", downloadedCharm)
+ return errgo.New("expected a charm archive, got %T", downloadedCharm)
}
archive, err := os.Open(downloadedBundle.Path)
if err != nil {
- return fmt.Errorf("cannot read downloaded charm: %v", err)
+ return errgo.Annotate(err, "cannot read downloaded charm")
}
defer archive.Close()
bundleSHA256, size, err := utils.ReadSHA256(archive)
if err != nil {
- return fmt.Errorf("cannot calculate SHA256 hash of charm: %v", err)
+ return errgo.Annotate(err, "cannot calculate SHA256 hash of charm")
}
if _, err := archive.Seek(0, 0); err != nil {
- return fmt.Errorf("cannot rewind charm archive: %v", err)
+ return errgo.Annotate(err, "cannot rewind charm archive")
}
// Get the environment storage and upload the charm.
env, err := environs.New(envConfig)
if err != nil {
- return fmt.Errorf("cannot access environment: %v", err)
+ return errgo.Annotate(err, "cannot access environment")
}
storage := env.Storage()
archiveName, err := CharmArchiveName(charmURL.Name, charmURL.Revision)
if err != nil {
- return fmt.Errorf("cannot generate charm archive name: %v", err)
+ return errgo.Annotate(err, "cannot generate charm archive name")
}
if err := storage.Put(archiveName, archive, size); err != nil {
- return fmt.Errorf("cannot upload charm to provider storage: %v", err)
+ return errgo.Annotate(err, "cannot upload charm to provider storage")
}
storageURL, err := storage.URL(archiveName)
if err != nil {
- return fmt.Errorf("cannot get storage URL for charm: %v", err)
+ return errgo.Annotate(err, "cannot get storage URL for charm")
}
bundleURL, err := url.Parse(storageURL)
if err != nil {
- return fmt.Errorf("cannot parse storage URL: %v", err)
+ return errgo.Annotate(err, "cannot parse storage URL")
}
// Finally, update the charm data in state and mark it as no longer pending.
@@ -903,7 +904,7 @@
// us. This means we have to delete what we just uploaded
// to storage.
if err := storage.Remove(archiveName); err != nil {
- logger.Errorf("cannot remove duplicated charm from storage: %v", err)
+ errgo.Annotate(err, "cannot remove duplicated charm from storage")
}
return nil
}

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b