wagoodman/dive · warning

could not stack tree range: %w

Error message

could not stack tree range: %w

What it means

Returned by StackTreeRange (dive/filetree/file_tree.go:386), which folds a range of layer trees into one. It wraps the error returned by FileTree.Stack for any layer in [start, stop]. Stack itself delegates to VisitDepthChildFirst whose graft callback always returns nil, so in stock code the wrapped error is essentially unreachable; per-path stacking failures are instead accumulated as PathError values in the second return value, which this error does not describe.

Source

Thrown at dive/filetree/file_tree.go:386

func (tree *FileTree) markRemoved(path string) error {
	node, err := tree.GetNode(path)
	if err != nil {
		return err
	}
	return node.AssignDiffType(Removed)
}

// StackTreeRange combines an array of trees into a single tree
func StackTreeRange(trees []*FileTree, start, stop int) (*FileTree, []PathError, error) {
	errors := make([]PathError, 0)
	tree := trees[0].Copy()
	for idx := start; idx <= stop; idx++ {
		failedPaths, err := tree.Stack(trees[idx])
		if len(failedPaths) > 0 {
			errors = append(errors, failedPaths...)
		}
		if err != nil {
			return nil, nil, fmt.Errorf("could not stack tree range: %w", err)
		}
	}
	return tree, errors, nil
}

View on GitHub (pinned to d6c691947f)

Solutions

  1. Inspect the wrapped error chain with errors.Unwrap/As - the %w keeps the original cause
  2. Confirm you are on stock dive and that the input trees were built by the library, not hand-constructed with nil payloads
  3. Report upstream with the wrapped cause if reproducible on unmodified code
Defensive patterns

Strategy: try-catch

Validate before calling

// guard the inputs StackTreeRange assumes: non-empty slice, valid range
tree, pathErrs, err := filetree.StackTreeRange(trees, start, stop)
if err != nil {
    if cause := errors.Unwrap(err); cause != nil {
        log.Printf("stack failure root cause: %v", cause)
    }
}

Try / catch

tree, failed, err := filetree.StackTreeRange(trees, start, stop)
if err != nil {
    return fmt.Errorf("stacking layers %d-%d: %w", start, stop, err)
}
// per-path failures are in `failed`, not `err` - log them separately:
for _, pe := range failed {
    log.Printf("path issue: %+v", pe)
}

Prevention

When it happens

Trigger: A tree visitor implementation that returns an error while grafting a layer (only possible in forks or custom visitor wrappers), since the bundled graft closure cannot fail.

Common situations: Not observed with upstream dive. If it appears, suspect a modified fork, a corrupted in-memory tree (nil children from earlier misuse), or a future regression in Stack.

Related errors


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