From 1a77680c3f5b66bab76bcce6e92cb7b0f1d01f33 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Thu, 6 Oct 2022 15:26:06 -0500 Subject: [PATCH] Make the corruption error more clear and fix zarf tools cache-clear (#852) --- src/cmd/tools.go | 5 +++-- src/internal/images/pull.go | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cmd/tools.go b/src/cmd/tools.go index 367f66fefe..1c43b53337 100644 --- a/src/cmd/tools.go +++ b/src/cmd/tools.go @@ -100,8 +100,9 @@ var clearCacheCmd = &cobra.Command{ Aliases: []string{"c"}, Short: "Clears the configured git and image cache directory", Run: func(cmd *cobra.Command, args []string) { - if err := os.RemoveAll(config.CreateOptions.CachePath); err != nil { - message.Fatalf("Unable to clear the cache driectory %s: %s", config.CreateOptions.CachePath, err.Error()) + message.Debugf("Cache directory set to: %s", config.GetAbsCachePath()) + if err := os.RemoveAll(config.GetAbsCachePath()); err != nil { + message.Fatalf("Unable to clear the cache driectory %s: %s", config.GetAbsCachePath(), err.Error()) } }, } diff --git a/src/internal/images/pull.go b/src/internal/images/pull.go index 515aceda3c..7a80dc972c 100644 --- a/src/internal/images/pull.go +++ b/src/internal/images/pull.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "path/filepath" + "strings" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/internal/message" @@ -44,7 +45,7 @@ func PullAll(buildImageList []string, imageTarballPath string) map[name.Tag]v1.I spinner.Updatef("Fetching image metadata (%d of %d): %s", idx+1, imageCount, src) img, err := crane.Pull(src, config.GetCraneOptions()...) if err != nil { - spinner.Fatalf(err, "Unable to pull the image %s", src) + spinner.Fatalf(err, "Unable to pull the image \"%s\"", src) } imageCachePath := filepath.Join(config.GetAbsCachePath(), config.ZarfImageCacheDir) img = cache.Image(img, cache.NewFilesystemCache(imageCachePath)) @@ -87,8 +88,11 @@ func PullAll(buildImageList []string, imageTarballPath string) map[name.Tag]v1.I case update.Error != nil && errors.Is(update.Error, io.EOF): progressBar.Success("Pulling %d images (%s)", len(imageMap), utils.ByteFormat(float64(update.Total), 2)) return tagToImage + case update.Error != nil && strings.HasPrefix(update.Error.Error(), "archive/tar: missed writing "): + // Handle potential image cache corruption with a more helpful error. See L#54 in libexec/src/archive/tar/writer.go + message.Fatalf(update.Error, "potential image cache corruption: %s of %v bytes - try clearing cache with \"zarf tools clear-cache\"", update.Error.Error(), update.Total) case update.Error != nil: - message.Fatal(update.Error, "error writing image tarball") + message.Fatalf(update.Error, "error writing image tarball: %s", update.Error.Error()) default: title = fmt.Sprintf("Pulling %d images (%s of %s)", len(imageMap), utils.ByteFormat(float64(update.Complete), 2),