{"record":{"id":"2a62fa22cfefbb60","repo":"mikefarah/yq","slug":"orderedmap-invalid-yaml-node","errorCode":null,"errorMessage":"orderedMap: invalid yaml node","messagePattern":"orderedMap: invalid yaml node","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/candidate_node_yaml.go","lineNumber":174,"sourceCode":"\t\t\tkeyNode.Kind = ScalarNode\n\t\t\tkeyNode.Value = fmt.Sprintf(\"%v\", i)\n\n\t\t\tvalueNode, err := o.decodeIntoChild(node.Content[i], anchorMap)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tvalueNode.Key = keyNode\n\t\t\to.Content[i] = valueNode\n\t\t}\n\t\treturn nil\n\tcase 0:\n\t\t// not sure when this happens\n\t\to.copyFromYamlNode(node, anchorMap)\n\t\tlog.Debugf(\"UnmarshalYAML -  err.. %v\", NodeToString(o))\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"orderedMap: invalid yaml node\")\n\t}\n}\n\nfunc (o *CandidateNode) MarshalYAML() (*yaml.Node, error) {\n\tlog.Debugf(\"MarshalYAML to yaml: %v\", o.Tag)\n\tswitch o.Kind {\n\tcase AliasNode:\n\t\tlog.Debugf(\"MarshalYAML - alias to yaml: %v\", o.Tag)\n\t\ttarget := &yaml.Node{Kind: yaml.AliasNode}\n\t\to.copyToYamlNode(target)\n\t\treturn target, nil\n\tcase ScalarNode:\n\t\tlog.Debugf(\"MarshalYAML - scalar: %v\", o.Value)\n\t\ttarget := &yaml.Node{Kind: yaml.ScalarNode}\n\t\to.copyToYamlNode(target)\n\t\treturn target, nil\n\tcase MappingNode, SequenceNode:\n\t\ttargetKind := yaml.MappingNode","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/candidate_node_yaml.go#L156-L192","documentation":"CandidateNode.UnmarshalYAML copies a yaml.Node (from gopkg.in/yaml.v3) into a CandidateNode by switching on the node Kind (document/mapping/sequence/alias/scalar, and 0 as a degenerate case). Any Kind value outside the known yaml.Kind set reaches the default branch and yields 'orderedMap: invalid yaml node'. It means the YAML library handed back a node kind yq does not recognise.","triggerScenarios":"Decoding YAML into CandidateNode where the underlying yaml.Node has an unexpected Kind — effectively only possible with a yaml library version introducing a new Kind, or corrupted/programmatically constructed yaml.Node values passed to Decode.","commonSituations":"Version mismatch between yq and gopkg.in/yaml.v3 (new Kind constant added upstream); Go code that builds yaml.Node structs manually with a zero-or-invalid Kind and feeds them to yq's decoder; nested custom UnmarshalYAML implementations returning malformed nodes.","solutions":["Check your gopkg.in/yaml.v3 version matches what yq's go.mod expects (`go mod tidy` / `go get gopkg.in/yaml.v3@<version>`) — a Kind mismatch is almost always a dependency drift.","If constructing yaml.Node values in Go, set Kind to a valid yaml.v3 kind (DocumentNode/SequenceNode/MappingNode/ScalarNode/AliasNode) before decoding.","Validate that any custom yaml.Node → yq bridges (custom UnmarshalYAML) return well-formed nodes; log node.Kind when reproducing.","Upgrade yq to the latest release, which tracks compatible yaml.v3 versions."],"exampleFix":"// before: manually built node with zero Kind\nnode := &yaml.Node{Value: \"hi\"} // Kind==0 or invalid → invalid yaml node\n// after\nnode := &yaml.Node{Kind: yaml.ScalarNode, Tag: \"!!str\", Value: \"hi\"}","handlingStrategy":"type-guard","validationCode":"// Go: check the yaml.Node kind before handing it to yq\nfunc isKnownYamlKind(n *yaml.Node) bool {\n    switch n.Kind {\n    case yaml.DocumentNode, yaml.SequenceNode, yaml.MappingNode,\n        yaml.ScalarNode, yaml.AliasNode, 0:\n        return true\n    }\n    return false\n}","typeGuard":"if !isKnownYamlKind(node) {\n    return fmt.Errorf(\"unsupported yaml node kind %d\", node.Kind)\n}","tryCatchPattern":"// Go\nif err := candidate.UnmarshalYAML(node); err != nil {\n    if strings.Contains(err.Error(), \"invalid yaml node\") {\n        return inspectAndRepairNode(node) // log node.Kind, rebuild valid node\n    }\n    return err\n}","preventionTips":["Pin gopkg.in/yaml.v3 to the version yq's go.mod requires","Never construct yaml.Node values with a zero/invalid Kind","Audit custom UnmarshalYAML bridges that wrap or clone yaml.Nodes"],"tags":["go","yq","yaml","deserialization"],"backgroundTag":"invalid-yaml-node-kind","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"}