{"record":{"id":"806e91afb90fb8ea","repo":"wagoodman/dive","slug":"unable-to-fetch-layer-tree-from-cache-w","errorCode":null,"errorMessage":"unable to fetch layer tree from cache: %w","messagePattern":"unable to fetch layer tree from cache: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/dive/cli/internal/ui/v1/viewmodel/filetree.go","lineNumber":115,"sourceCode":"func (vm *FileTreeViewModel) IsVisible() bool {\n\treturn vm != nil\n}\n\n// ResetCursor moves the cursor back to the top of the buffer and translates to the top of the buffer.\nfunc (vm *FileTreeViewModel) ResetCursor() {\n\tvm.TreeIndex = 0\n\tvm.bufferIndex = 0\n\tvm.bufferIndexLowerBound = 0\n}\n\n// SetTreeByLayer populates the view model by stacking the indicated image layer file trees.\nfunc (vm *FileTreeViewModel) SetTreeByLayer(bottomTreeStart, bottomTreeStop, topTreeStart, topTreeStop int) error {\n\tif topTreeStop > len(vm.RefTrees)-1 {\n\t\treturn fmt.Errorf(\"invalid layer index given: %d of %d\", topTreeStop, len(vm.RefTrees)-1)\n\t}\n\tnewTree, err := vm.comparer.GetTree(filetree.NewTreeIndexKey(bottomTreeStart, bottomTreeStop, topTreeStart, topTreeStop))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to fetch layer tree from cache: %w\", err)\n\t}\n\n\t// preserve vm state on copy\n\tvisitor := func(node *filetree.FileNode) error {\n\t\tnewNode, err := newTree.GetNode(node.Path())\n\t\tif err == nil {\n\t\t\tnewNode.Data.ViewInfo = node.Data.ViewInfo\n\t\t}\n\t\treturn nil\n\t}\n\terr = vm.ModelTree.VisitDepthChildFirst(visitor, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to propagate layer tree: %w\", err)\n\t}\n\n\tvm.ModelTree = newTree\n\treturn nil\n}","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/wagoodman/dive/blob/d6c691947f8fda635c952a17ee3b7555379d58f0/cmd/dive/cli/internal/ui/v1/viewmodel/filetree.go#L97-L133","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the wrapped error for the specific stacking/compare cause and the offending layer","Re-pull the image (docker pull) to rule out a truncated or corrupted download, then retry dive","Try analyzing a derived tag or rebuilding the image to isolate the problematic layer","Report upstream (github.com/wagoodman/dive) with the image reference and full error chain if reproducible"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"tree, err := vm.comparer.GetTree(key)\nif err != nil {\n    return fmt.Errorf(\"unable to fetch layer tree from cache: %w\", err)\n    // inspect errors.Unwrap chain: 'could not stack tree range' => image data issue\n}","preventionTips":["Re-pull images when layer data is suspect","Keep the comparer cache warm via BuildCache at startup to fail early and once","Log the full unwrap chain for diagnosis"],"tags":["filetree","comparer","layer-stacking","image-data"],"backgroundTag":null,"analyzedSha":"d6c691947f8fda635c952a17ee3b7555379d58f0","analyzedAt":"2026-08-15T09:42:35.293Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}