{"record":{"id":"f474d57035a036b1","repo":"mikefarah/yq","slug":"cannot-delete-nodes-from-parent-of-tag-v","errorCode":null,"errorMessage":"cannot delete nodes from parent of tag %v","messagePattern":"cannot delete nodes from parent of tag (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_delete.go","lineNumber":35,"sourceCode":"\n\t\tif candidate.Parent == nil {\n\t\t\t// must be a top level thing, delete it\n\t\t\treturn removeFromContext(context, candidate)\n\t\t}\n\t\tlog.Debugf(\"processing deletion of candidate %v\", NodeToString(candidate))\n\n\t\tparentNode := candidate.Parent\n\n\t\tcandidatePath := candidate.GetPath()\n\t\tchildPath := candidatePath[len(candidatePath)-1]\n\n\t\tswitch parentNode.Kind {\n\t\tcase MappingNode:\n\t\t\tdeleteFromMap(candidate.Parent, childPath)\n\t\tcase SequenceNode:\n\t\t\tdeleteFromArray(candidate.Parent, childPath)\n\t\tdefault:\n\t\t\treturn Context{}, fmt.Errorf(\"cannot delete nodes from parent of tag %v\", parentNode.Tag)\n\t\t}\n\t}\n\treturn context, nil\n}\n\nfunc removeFromContext(context Context, candidate *CandidateNode) (Context, error) {\n\tnewResults := list.New()\n\tfor item := context.MatchingNodes.Front(); item != nil; item = item.Next() {\n\t\tnodeInContext := item.Value.(*CandidateNode)\n\t\tif nodeInContext != candidate {\n\t\t\tnewResults.PushBack(nodeInContext)\n\t\t} else {\n\t\t\tlog.Infof(\"Need to delete this %v\", NodeToString(nodeInContext))\n\t\t}\n\t}\n\treturn context.ChildContext(newResults), nil\n}\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_delete.go#L17-L53","documentation":"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.","triggerScenarios":"Thrown at pkg/yqlib/operator_delete.go:35 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}