From 2d649e248734c28e537e94e09dbe2ca980ee092c Mon Sep 17 00:00:00 2001 From: Yiran Wang Date: Wed, 28 Nov 2018 17:19:16 -0800 Subject: [PATCH] Fix typos and wrap errors (#82) * Fix typo * Fix golint warnings * wrap errors * fix * fix --- cli/application.go | 6 +++--- lib/builder/build_stage.go | 2 +- lib/cache/fs_store.go | 19 ++++++++++++------- lib/context/build_context.go | 2 +- lib/snapshot/testutils_test.go | 12 +++--------- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/cli/application.go b/cli/application.go index e1596375..b5fe70eb 100644 --- a/cli/application.go +++ b/cli/application.go @@ -97,18 +97,18 @@ func (app *BuildApplication) PostFlagParse() error { logger, err := app.getLogger() if err != nil { - return fmt.Errorf("build logger: %v", err) + return fmt.Errorf("build logger: %s", err) } log.SetLogger(logger.Sugar()) if app.Profile { if err := app.setupProfiler(); err != nil { - return fmt.Errorf("setup profiler: %v", err) + return fmt.Errorf("setup profiler: %s", err) } } if err := app.BuildFlags.postInit(); err != nil { - return err + return fmt.Errorf("process flags: %s", err) } return nil } diff --git a/lib/builder/build_stage.go b/lib/builder/build_stage.go index 9b3c63d0..8a665e0a 100644 --- a/lib/builder/build_stage.go +++ b/lib/builder/build_stage.go @@ -225,7 +225,7 @@ func (stage *buildStage) saveImage(store storage.ImageStore, repo, tag string) ( } manifestPath := manifestFile.Name() - // Remove temp file after hardlinked to manifest store + // Remove temp file after hard-linked to manifest store defer os.Remove(manifestPath) if err := ioutil.WriteFile(manifestPath, manifestJSON, 0755); err != nil { diff --git a/lib/cache/fs_store.go b/lib/cache/fs_store.go index e076e77b..3f53cace 100644 --- a/lib/cache/fs_store.go +++ b/lib/cache/fs_store.go @@ -16,6 +16,7 @@ package cache import ( "encoding/json" + "fmt" "io/ioutil" "os" "sync" @@ -52,11 +53,11 @@ func NewFSStore(fullpath string, sandboxDir string, ttlsec int64) (KVStore, erro if os.IsNotExist(err) { return s, nil } else if err != nil { - return nil, err + return nil, fmt.Errorf("read cache id file: %s", err) } if err := json.Unmarshal(contents, &s.entries); err != nil { if err := os.Remove(fullpath); err != nil { - return nil, err + return nil, fmt.Errorf("remove cache id file: %s", err) } return s, nil } @@ -99,20 +100,20 @@ func (s *fsStore) Put(key, value string) error { content, err := json.Marshal(s.entries) if err != nil { - return err + return fmt.Errorf("marshal cache id file: %s", err) } tempFile, err := ioutil.TempFile(s.sandboxDir, "cache") if err != nil { - return err + return fmt.Errorf("create temp cache id file: %s", err) } defer os.Remove(tempFile.Name()) if err := ioutil.WriteFile(tempFile.Name(), content, 0755); err != nil { - return err + return fmt.Errorf("write to temp cache id file: %s", err) } if err := os.Rename(tempFile.Name(), s.fullpath); err != nil { - return err + return fmt.Errorf("rename cache id file: %s", err) } return nil @@ -124,5 +125,9 @@ func (s *fsStore) Cleanup() error { s.entries = make(map[string]*cacheEntry) - return os.Remove(s.fullpath) + if err := os.Remove(s.fullpath); err != nil { + return fmt.Errorf("remove cache id file: %s", err) + } + + return nil } diff --git a/lib/context/build_context.go b/lib/context/build_context.go index 99de5b9e..5a67b384 100644 --- a/lib/context/build_context.go +++ b/lib/context/build_context.go @@ -43,7 +43,7 @@ type BuildContext struct { // persisted. StageVars map[string]string - // MemFS and ImageStore can be shared accross all copies of the BuildContext. + // MemFS and ImageStore can be shared across all copies of the BuildContext. MemFS *snapshot.MemFS // Merged view of base layers. Layers should be merged in order. ImageStore storage.ImageStore // Stores image layers and manifests. diff --git a/lib/snapshot/testutils_test.go b/lib/snapshot/testutils_test.go index 79ee3787..10fe5e30 100644 --- a/lib/snapshot/testutils_test.go +++ b/lib/snapshot/testutils_test.go @@ -201,7 +201,7 @@ func findNode(fs *MemFS, p string, followSymlink bool, depth int) (*memFSNode, e } func writeTarHelper(m *memFile, srcRoot string, w *tar.Writer) error { - if err := filepath.Walk(srcRoot, func(p string, fi os.FileInfo, err error) error { + return filepath.Walk(srcRoot, func(p string, fi os.FileInfo, err error) error { if err != nil { return err } @@ -213,14 +213,8 @@ func writeTarHelper(m *memFile, srcRoot string, w *tar.Writer) error { return err } - if err := tario.WriteEntry(w, p, h); err != nil { - return err - } - return nil - }); err != nil { - return err - } - return nil + return tario.WriteEntry(w, p, h) + }) } func readTarHelper(r *tar.Reader) (map[string]*tar.Header, error) {