From c7a356aabc2cb1536e48e7318f2c992bf2698e9b Mon Sep 17 00:00:00 2001 From: Timur Tuktamyshev Date: Wed, 28 Jan 2026 20:41:34 +0300 Subject: [PATCH] fix: improve error verbosity in NEW_PULL and NEW_PUSH paths Signed-off-by: Timur Tuktamyshev --- internal/mirror/cmd/pull/pull.go | 4 ++-- internal/mirror/cmd/push/push.go | 6 +++--- internal/mirror/modules/modules.go | 2 +- internal/mirror/platform/platform.go | 4 ++-- internal/mirror/puller/puller.go | 6 +++--- internal/mirror/push.go | 14 +++++++------- internal/mirror/pusher/pusher.go | 2 +- internal/mirror/security/security.go | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/internal/mirror/cmd/pull/pull.go b/internal/mirror/cmd/pull/pull.go index 56d4ce7f..57b6ec97 100644 --- a/internal/mirror/cmd/pull/pull.go +++ b/internal/mirror/cmd/pull/pull.go @@ -121,7 +121,7 @@ func pull(cmd *cobra.Command, _ []string) error { puller.logger.WarnLn("Operation cancelled by user") return nil } - return ErrPullFailed + return fmt.Errorf("pull failed: %w", err) } return nil @@ -307,7 +307,7 @@ func (p *Puller) Execute(ctx context.Context) error { p.logger.WarnLn("Operation cancelled by user") return nil } - return err + return fmt.Errorf("pull from registry: %w", err) } return nil diff --git a/internal/mirror/cmd/push/push.go b/internal/mirror/cmd/push/push.go index af3a0452..2bf9e68e 100644 --- a/internal/mirror/cmd/push/push.go +++ b/internal/mirror/cmd/push/push.go @@ -170,7 +170,7 @@ func pushStaticPackages(pushParams *params.PushParams, logger params.Logger, cli logger.InfoLn(pkgName, "package is not present, skipping") continue case err != nil: - return err + return fmt.Errorf("open package %q: %w", pkgName, err) } switch pkgName { @@ -236,7 +236,7 @@ func validateRegistryAccess(ctx context.Context, pushParams *params.PushParams) accessValidator := validation.NewRemoteRegistryAccessValidator() err := accessValidator.ValidateWriteAccessForRepo(ctx, path.Join(pushParams.RegistryHost, pushParams.RegistryPath), opts...) if err != nil { - return err + return fmt.Errorf("validate write access to registry %s: %w", path.Join(pushParams.RegistryHost, pushParams.RegistryPath), err) } return nil @@ -359,7 +359,7 @@ func (p *Pusher) executeNewPush() error { p.logger.WarnLn("Operation cancelled by user") return nil } - return err + return fmt.Errorf("push to registry: %w", err) } return nil diff --git a/internal/mirror/modules/modules.go b/internal/mirror/modules/modules.go index f6dfc5f0..c3580a66 100644 --- a/internal/mirror/modules/modules.go +++ b/internal/mirror/modules/modules.go @@ -145,7 +145,7 @@ func (svc *Service) validateModulesAccess(ctx context.Context) error { } if err != nil { - return fmt.Errorf("failed to check modules lists: %w", err) + return fmt.Errorf("failed to list modules from registry: %w", err) } return nil diff --git a/internal/mirror/platform/platform.go b/internal/mirror/platform/platform.go index 2cfca9b6..d4c68b83 100644 --- a/internal/mirror/platform/platform.go +++ b/internal/mirror/platform/platform.go @@ -159,7 +159,7 @@ func (svc *Service) validatePlatformAccess(ctx context.Context) error { if internal.ChannelIsValid(targetTag) { err := svc.deckhouseService.ReleaseChannels().CheckImageExists(ctx, targetTag) if err != nil { - return fmt.Errorf("failed to check release exists: %w", err) + return fmt.Errorf("failed to check release channel %q exists in registry: %w", targetTag, err) } return nil @@ -168,7 +168,7 @@ func (svc *Service) validatePlatformAccess(ctx context.Context) error { // For specific tags, check if the tag exists err := svc.deckhouseService.CheckImageExists(ctx, targetTag) if err != nil { - return fmt.Errorf("failed to check tag exists: %w", err) + return fmt.Errorf("failed to check Deckhouse tag %q exists in registry: %w", targetTag, err) } return nil diff --git a/internal/mirror/puller/puller.go b/internal/mirror/puller/puller.go index e940db91..0af11292 100644 --- a/internal/mirror/puller/puller.go +++ b/internal/mirror/puller/puller.go @@ -89,7 +89,7 @@ func (ps *PullerService) PullImages(ctx context.Context, config PullConfig) erro continue } - return fmt.Errorf("get digest: %w", err) + return fmt.Errorf("get digest for image %s: %w", tag, err) } config.ImageSet[image] = NewImageMeta(tag, image, digest) @@ -135,7 +135,7 @@ func (ps *PullerService) PullImageSet( if err != nil { logger.Debugf("failed to pull image %s: %v", imageMeta.TagReference, err) - return fmt.Errorf("pull image metadata: %w", err) + return fmt.Errorf("pull image %s (digest %s): %w", imageMeta.TagReference, imageMeta.Digest.String(), err) } img.SetMetadata(&image.ImageMeta{ @@ -148,7 +148,7 @@ func (ps *PullerService) PullImageSet( if err != nil { logger.Debugf("failed to add image %s: %v", imageMeta.ImageTag, err) - return fmt.Errorf("add image to layout: %w", err) + return fmt.Errorf("add image %s to layout: %w", imageMeta.ImageTag, err) } return nil diff --git a/internal/mirror/push.go b/internal/mirror/push.go index 37fc1e23..e3f7b689 100644 --- a/internal/mirror/push.go +++ b/internal/mirror/push.go @@ -153,7 +153,7 @@ func (svc *PushService) unpackAllPackages(ctx context.Context, dirPath string) e packages := svc.findPackages(entries) if len(packages) == 0 { - return fmt.Errorf("no packages found in bundle directory") + return fmt.Errorf("no packages found in bundle directory %q", svc.options.BundleDir) } svc.userLogger.Infof("Found %d packages to unpack", len(packages)) @@ -227,7 +227,7 @@ func (svc *PushService) openPackage(pkgName string) (io.ReadCloser, error) { } if !os.IsNotExist(err) { - return nil, fmt.Errorf("open %s: %w", tarPath, err) + return nil, fmt.Errorf("open tar package %q: %w", tarPath, err) } // Try chunked format @@ -239,7 +239,7 @@ func (svc *PushService) openPackage(pkgName string) (io.ReadCloser, error) { func (svc *PushService) pushAllLayouts(ctx context.Context, rootDir string) error { layouts, err := svc.findLayouts(rootDir) if err != nil { - return fmt.Errorf("scan layouts: %w", err) + return fmt.Errorf("scan layouts in %q: %w", rootDir, err) } if len(layouts) == 0 { @@ -317,7 +317,7 @@ func (svc *PushService) pushSingleLayout(ctx context.Context, rootDir, layoutDir svc.userLogger.Infof("Pushing %s", targetClient.GetRegistry()) if err := svc.pusher.PushLayout(ctx, layout.Path(layoutDir), targetClient); err != nil { - return fmt.Errorf("push layout %q: %w", relPath, err) + return fmt.Errorf("push layout %q to registry %s: %w", relPath, targetClient.GetRegistry(), err) } return nil @@ -352,7 +352,7 @@ func (svc *PushService) createModulesIndex(ctx context.Context, rootDir string) svc.userLogger.InfoLn("No modules directory found, skipping modules index") return nil } - return fmt.Errorf("read modules directory: %w", err) + return fmt.Errorf("read modules directory %q: %w", modulesDir, err) } // Find all module directories @@ -385,12 +385,12 @@ func (svc *PushService) createModulesIndex(ctx context.Context, rootDir string) // Create minimal random image (32 bytes, 1 layer) img, err := random.Image(32, 1) if err != nil { - return fmt.Errorf("create random image for module %s: %w", moduleName, err) + return fmt.Errorf("create random image for module discovery tag %s: %w", moduleName, err) } // Push with module name as tag if err := modulesClient.PushImage(ctx, moduleName, img); err != nil { - return fmt.Errorf("push module index tag %s: %w", moduleName, err) + return fmt.Errorf("push module index tag %s to registry %s: %w", moduleName, modulesClient.GetRegistry(), err) } } diff --git a/internal/mirror/pusher/pusher.go b/internal/mirror/pusher/pusher.go index e093abff..89dcac52 100644 --- a/internal/mirror/pusher/pusher.go +++ b/internal/mirror/pusher/pusher.go @@ -96,7 +96,7 @@ func (s *Service) PushLayout(ctx context.Context, layoutPath layout.Path, client img, err := index.Image(manifest.Digest) if err != nil { - return fmt.Errorf("read image %s: %w", tag, err) + return fmt.Errorf("read image %s from layout %s: %w", tag, layoutPath, err) } imageReferenceString := fmt.Sprintf("%s:%s", client.GetRegistry(), tag) diff --git a/internal/mirror/security/security.go b/internal/mirror/security/security.go index ab174dff..e8897a14 100644 --- a/internal/mirror/security/security.go +++ b/internal/mirror/security/security.go @@ -130,7 +130,7 @@ func (svc *Service) validateSecurityAccess(ctx context.Context) error { } if err != nil { - return fmt.Errorf("failed to check tag exists: %w", err) + return fmt.Errorf("failed to check security database tag %q in registry: %w", "2", err) } return nil