wagoodman/dive · warning
could not add child node: '%s' (path:'%s')
Error message
could not add child node: '%s' (path:'%s')
What it means
Returned by FileTree.AddPath (dive/filetree/file_tree.go:272) when FileNode.AddChild returns nil for an intermediary path segment. In this version AddChild (file_node.go:90) returns nil only for names with the double-whiteout prefix (.wh..wh..), which AddPath itself already screens before calling AddChild - so the branch is defensive/unreachable in stock flows. Note the code also appends the nil node to addedNodes before checking, so callers see a nil entry in the slice too.
Source
Thrown at dive/filetree/file_tree.go:272
continue
}
// find or create node
if node.Children[name] != nil {
node = node.Children[name]
} else {
// don't add paths that should be deleted
if strings.HasPrefix(name, doubleWhiteoutPrefix) {
return nil, addedNodes, nil
}
// don't attach the payload. The payload is destined for the
// Path's end node, not any intermediary node.
node = node.AddChild(name, FileInfo{})
addedNodes = append(addedNodes, node)
if node == nil {
// the child could not be added
return node, addedNodes, fmt.Errorf("could not add child node: '%s' (path:'%s')", name, filepath)
}
}
// attach payload to the last specified node
if idx == len(nodeNames)-1 {
node.Data.FileInfo = data
}
}
return node, addedNodes, nil
}
// RemovePath removes a node from the tree given its path.
func (tree *FileTree) RemovePath(path string) error {
node, err := tree.GetNode(path)
if err != nil {
return err
}
return node.Remove()View on GitHub (pinned to d6c691947f)
Solutions
- Sanitize whiteout-prefixed segments before calling AddPath: strip or reject names starting with '.wh.'
- Check both the error and for nil entries in returned addedNodes if you drive this API directly
- If you maintain a fork, make AddChild's nil conditions explicit and align them with AddPath's prefix filter
Defensive patterns
Strategy: validation
Validate before calling
// strip whiteout-style segments before driving AddPath
func safeSegments(p string) bool {
for _, seg := range strings.Split(strings.Trim(p, "/"), "/") {
if strings.HasPrefix(seg, ".wh.") {
return false
}
}
return true
} Try / catch
node, added, err := tree.AddPath(p, data)
if err != nil && strings.Contains(err.Error(), "could not add child node") {
log.Printf("dropping whiteout-ish path %s", p)
err = nil // this branch is defensive-only upstream
} Prevention
- Sanitize '.wh.'-prefixed names before tree construction
- Never hand-construct nodes bypassing AddPath/AddChild contracts
- Nil-check entries in returned addedNodes if you consume that slice
When it happens
Trigger: Adding a path containing a segment named '.wh..wh..-*' that evades the HasPrefix check in AddPath (e.g. after path.Clean normalization differences), or a fork of AddChild that can return nil for invalid payloads.
Common situations: Almost never fires upstream. Appears in forks/tests that inject failing AddChild behavior or hand-craft whiteout-prefixed path segments.
Related errors
- could not stack tree range: %w
- path error at layer index %s: %s
- unable to write to hash: %w
- file tree has path errors (use '--ignore-errors' to attempt
- notifyOnViewOptionChangeListeners error: %w
AI-assisted analysis of wagoodman/dive@d6c691947f (2026-08-15).
Data as JSON: /api/errors/fd616d2448742835.
Report an issue: GitHub.