{"record":{"id":"5740558929c4a028","repo":"wagoodman/dive","slug":"failed-to-build-tree-w","errorCode":null,"errorMessage":"failed to build tree: %w","messagePattern":"failed to build tree: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dive/filetree/comparer.go","lineNumber":79,"sourceCode":"\tvalue, pathErrors, err := cmp.get(key)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tcmp.trees[key] = value\n\tcmp.pathErrors[key] = pathErrors\n\treturn value, nil\n}\n\nfunc (cmp *Comparer) get(key TreeIndexKey) (*FileTree, []PathError, error) {\n\tnewTree, pathErrors, err := StackTreeRange(cmp.refTrees, key.bottomTreeStart, key.bottomTreeStop)\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\tfor idx := key.topTreeStart; idx <= key.topTreeStop; idx++ {\n\t\tmarkPathErrors, err := newTree.CompareAndMark(cmp.refTrees[idx])\n\t\tpathErrors = append(pathErrors, markPathErrors...)\n\t\tif err != nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"failed to build tree: %w\", err)\n\t\t}\n\t}\n\treturn newTree, pathErrors, nil\n}\n\n// case 1: layer compare (top tree SIZE is fixed (BUT floats forward), Bottom tree SIZE changes)\nfunc (cmp *Comparer) NaturalIndexes() <-chan TreeIndexKey {\n\tindexes := make(chan TreeIndexKey)\n\n\tgo func() {\n\t\tdefer close(indexes)\n\n\t\tvar bottomTreeStart, bottomTreeStop, topTreeStart, topTreeStop int\n\n\t\tfor selectIdx := 0; selectIdx < len(cmp.refTrees); selectIdx++ {\n\t\t\tbottomTreeStart = 0\n\t\t\ttopTreeStop = selectIdx\n","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/wagoodman/dive/blob/d6c691947f8fda635c952a17ee3b7555379d58f0/dive/filetree/comparer.go#L61-L97","documentation":"Inside the filetree Comparer's get(), after stacking the bottom tree range, each top-layer tree is compared and merged via CompareAndMark; any error from that step is wrapped as 'failed to build tree'. This is the comparer's generic failure for being unable to merge an upper layer onto the stacked lower tree — typically from AssignDiffType/deriveDiffType rejecting an operation on inconsistent tree state, or the stack step failing upstream.","triggerScenarios":"newTree.CompareAndMark(cmp.refTrees[idx]) returning non-nil for any idx in [topTreeStart, topTreeStop]: graft-time AddPath failures are captured as PathErrors (non-fatal), but AssignDiffType or deriveDiffType errors abort the build. Occurs during GetTree cache misses — i.e. first render of a layer selection or BuildCache warm-up.","commonSituations":"Images with unusual whiteout semantics (deleting paths absent from lower layers in conflicting ways), non-standard layer payloads from niche builders, corrupted layers from a bad pull, or programmatic misuse of NewTreeIndexKey with out-of-range bounds causing refTrees[idx] lookups on inconsistent ranges.","solutions":["Check the wrapped error for the exact failing operation (assign/derive diff type vs stack range)","Re-pull or rebuild the image to eliminate corrupted layer data, then retry","Simplify reproduction: analyze a single-layer derivative (docker save/squash) to find the offending layer pair","Report upstream with the image reference and full error chain"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// programmatic use: validate key bounds before GetTree\nn := len(cmp.RefTrees)\nif key.bottomTreeStart < 0 || key.bottomTreeStop >= n || key.topTreeStop >= n {\n    return errors.New(\"tree index key out of range\")\n}","typeGuard":null,"tryCatchPattern":"tree, err := cmp.GetTree(key)\nif err != nil {\n    return nil, fmt.Errorf(\"build tree %s: %w\", key, err) // key.String() aids debugging\n}","preventionTips":["Use the comparer's own index generators (NaturalIndexes/AggregatedIndexes) instead of hand-built keys","Validate refTrees slices are non-empty and consistent before comparing","Warm the cache at startup to surface bad layers once, early"],"tags":["filetree","comparer","diff","image-data"],"backgroundTag":null,"analyzedSha":"d6c691947f8fda635c952a17ee3b7555379d58f0","analyzedAt":"2026-08-15T09:42:35.293Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}