wagoodman/dive · error

unable to fetch layer tree from cache: %w

Error message

unable to fetch layer tree from cache: %w

What it means

SetTreeByLayer wraps any error from the filetree Comparer's GetTree, which builds (and caches) a stacked tree for the requested layer range. The underlying cause is usually 'could not stack tree range' (from StackTreeRange) or a compare/mark failure (from CompareAndMark) — i.e. the image's layer trees could not be combined for the requested index range.

Source

Thrown at cmd/dive/cli/internal/ui/v1/viewmodel/filetree.go:115

func (vm *FileTreeViewModel) IsVisible() bool {
	return vm != nil
}

// ResetCursor moves the cursor back to the top of the buffer and translates to the top of the buffer.
func (vm *FileTreeViewModel) ResetCursor() {
	vm.TreeIndex = 0
	vm.bufferIndex = 0
	vm.bufferIndexLowerBound = 0
}

// SetTreeByLayer populates the view model by stacking the indicated image layer file trees.
func (vm *FileTreeViewModel) SetTreeByLayer(bottomTreeStart, bottomTreeStop, topTreeStart, topTreeStop int) error {
	if topTreeStop > len(vm.RefTrees)-1 {
		return fmt.Errorf("invalid layer index given: %d of %d", topTreeStop, len(vm.RefTrees)-1)
	}
	newTree, err := vm.comparer.GetTree(filetree.NewTreeIndexKey(bottomTreeStart, bottomTreeStop, topTreeStart, topTreeStop))
	if err != nil {
		return fmt.Errorf("unable to fetch layer tree from cache: %w", err)
	}

	// preserve vm state on copy
	visitor := func(node *filetree.FileNode) error {
		newNode, err := newTree.GetNode(node.Path())
		if err == nil {
			newNode.Data.ViewInfo = node.Data.ViewInfo
		}
		return nil
	}
	err = vm.ModelTree.VisitDepthChildFirst(visitor, nil)
	if err != nil {
		return fmt.Errorf("unable to propagate layer tree: %w", err)
	}

	vm.ModelTree = newTree
	return nil
}

View on GitHub (pinned to d6c691947f)

Solutions

  1. Check the wrapped error for the specific stacking/compare cause and the offending layer
  2. Re-pull the image (docker pull) to rule out a truncated or corrupted download, then retry dive
  3. Try analyzing a derived tag or rebuilding the image to isolate the problematic layer
  4. Report upstream (github.com/wagoodman/dive) with the image reference and full error chain if reproducible
Defensive patterns

Strategy: try-catch

Try / catch

tree, err := vm.comparer.GetTree(key)
if err != nil {
    return fmt.Errorf("unable to fetch layer tree from cache: %w", err)
    // inspect errors.Unwrap chain: 'could not stack tree range' => image data issue
}

Prevention

When it happens

Trigger: Comparer.GetTree(key) failing: StackTreeRange erroring while applying layer diffs (Stack failing on a malformed layer), or CompareAndMark failing (e.g. AssignDiffType/deriveDiffType errors on inconsistent tree state). Happens when switching layers or building the initial tree for an image with unusual layer contents.

Common situations: Images with odd whiteout entries (.wh. files referencing missing paths in surprising ways), corrupted or non-standard OCI/Docker layers, images built by exotic builders (e.g. some buildkit or distroless edge cases), or truncated image data fetched from a registry.

Related errors


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