mikefarah/yq · error
cannot delete nodes from parent of tag %v
Error message
cannot delete nodes from parent of tag %v
What it means
delete ('del') resolved a candidate that has a Parent, but that parent is neither a MappingNode nor a SequenceNode — the only two containers from which a child can be removed by key/index. The parent's tag is printed; typically the node's Parent pointer points at a scalar/alias artefact rather than a real collection, indicating an unexpected tree shape.
Source
Thrown at pkg/yqlib/operator_delete.go:35
if candidate.Parent == nil {
// must be a top level thing, delete it
return removeFromContext(context, candidate)
}
log.Debugf("processing deletion of candidate %v", NodeToString(candidate))
parentNode := candidate.Parent
candidatePath := candidate.GetPath()
childPath := candidatePath[len(candidatePath)-1]
switch parentNode.Kind {
case MappingNode:
deleteFromMap(candidate.Parent, childPath)
case SequenceNode:
deleteFromArray(candidate.Parent, childPath)
default:
return Context{}, fmt.Errorf("cannot delete nodes from parent of tag %v", parentNode.Tag)
}
}
return context, nil
}
func removeFromContext(context Context, candidate *CandidateNode) (Context, error) {
newResults := list.New()
for item := context.MatchingNodes.Front(); item != nil; item = item.Next() {
nodeInContext := item.Value.(*CandidateNode)
if nodeInContext != candidate {
newResults.PushBack(nodeInContext)
} else {
log.Infof("Need to delete this %v", NodeToString(nodeInContext))
}
}
return context.ChildContext(newResults), nil
}
View on GitHub (pinned to 8b5af0694b)
Solutions
- Delete by path from the document root instead: del(.a.b.c)
- Ensure the target expression resolves to map entries or array elements
- Re-explode anchors/aliases before deleting if the tree came from aliased YAML
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pkg/yqlib/operator_delete.go:35 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05).
Data as JSON: /api/errors/f474d57035a036b1.
Report an issue: GitHub.