wagoodman/dive · critical

cannot analyze image: %w

Error message

cannot analyze image: %w

What it means

Returned from run() when the analyzer fails while processing the fetched image (adapter.NewAnalyzer().Analyze). At this point the image was fetched successfully; the failure is in reading layer metadata/tarballs and building the file tree — unsupported compression, corrupt layer blobs, or an engine API incompatibility.

Source

Thrown at cmd/dive/cli/internal/command/root.go:77

		},
	}, opts)
}

func setUI(app clio.Application, opts options.Application) error {
	type Stater interface {
		State() *clio.State
	}

	state := app.(Stater).State()

	ux := ui.NewV1UI(opts.V1Preferences(), os.Stdout, state.Config.Log.Quiet, state.Config.Log.Verbosity)
	return state.UI.Replace(ux)
}

func run(ctx context.Context, opts options.Application, img *image.Image, content image.ContentReader) error {
	analysis, err := adapter.NewAnalyzer().Analyze(ctx, img)
	if err != nil {
		return fmt.Errorf("cannot analyze image: %w", err)
	}

	if opts.Export.JsonPath != "" {
		if err := adapter.NewExporter(afero.NewOsFs()).ExportTo(ctx, analysis, opts.Export.JsonPath); err != nil {
			return fmt.Errorf("cannot export analysis: %w", err)
		}
		return nil
	}

	if opts.CI.Enabled {
		eval := adapter.NewEvaluator(opts.CI.Rules.List).Evaluate(ctx, analysis)

		if !eval.Pass {
			return errors.New("evaluation failed")
		}
		return nil
	}

View on GitHub (pinned to d6c691947f)

Solutions

  1. Read the wrapped error to see which layer/step failed
  2. Re-pull the image from scratch (docker rmi + pull) to replace corrupted blobs
  3. Upgrade dive to a release matching your engine version
  4. Try the other engine as source or docker save/load the image to normalize its layout

Example fix

# before (possibly corrupt local layers)
dive myapp:latest

# after (force clean re-fetch)
docker rmi myapp:latest && docker pull myapp:latest && dive myapp:latest
Defensive patterns

Strategy: retry

Validate before calling

// verify layer blobs are readable before full analysis
for _, l := range img.Layers {
    if _, err := io.Copy(io.Discard, l.Reader()); err != nil {
        return fmt.Errorf("layer unreadable, re-pull image: %w", err)
    }
}

Try / catch

analysis, err := adapter.NewAnalyzer().Analyze(ctx, img)
if err != nil {
    if isCorruption(err) { // truncated blob: re-pull once, then retry
        if rp := repull(ctx, img.Request); rp == nil {
            analysis, err = adapter.NewAnalyzer().Analyze(ctx, img)
        }
    }
    if err != nil { return fmt.Errorf("cannot analyze image: %w", err) }
}

Prevention

When it happens

Trigger: Analyze(ctx, img) on an image whose layer tarballs are corrupt or truncated, use compression schemes the analyzer cannot decode, or whose metadata layout does not match what the analyzer expects from this engine version.

Common situations: Interrupted docker pull leaving a partial layer in the cache; images pushed with experimental OCI media types by newer build tooling than dive supports; analyzing very large images that exhaust memory during tree construction; podman/docker major-version changes to storage layout.

Related errors


AI-assisted analysis of wagoodman/dive@d6c691947f (2026-08-15). Data as JSON: /api/errors/b7b9b1eba48cbeca. Report an issue: GitHub.