{"record":{"id":"c4fe439b8e2a3fd7","repo":"mikefarah/yq","slug":"unsupported-type-v-c4fe43","errorCode":null,"errorMessage":"unsupported type %v","messagePattern":"unsupported type (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/encoder_xml.go","lineNumber":201,"sourceCode":"\tcase ScalarNode:\n\t\terr := e.encodeStart(encoder, node, start)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tvar charData xml.CharData = []byte(node.Value)\n\t\terr = encoder.EncodeToken(charData)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif err = e.encodeComment(encoder, lineComment(node)); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\treturn e.encodeEnd(encoder, node, start)\n\t}\n\treturn fmt.Errorf(\"unsupported type %v\", node.Tag)\n}\n\nvar xmlEncodeMultilineCommentRegex = regexp.MustCompile(`(^|\\n) *# ?(.*)`)\nvar xmlEncodeSingleLineCommentRegex = regexp.MustCompile(`^\\s*#(.*)\\n?`)\nvar chompRegexp = regexp.MustCompile(`\\n$`)\n\nfunc (e *xmlEncoder) encodeComment(encoder *xml.Encoder, commentStr string) error {\n\tif commentStr != \"\" {\n\t\tlog.Debugf(\"got comment [%v]\", commentStr)\n\t\t// multi line string\n\t\tif len(commentStr) > 2 && strings.Contains(commentStr[1:len(commentStr)-1], \"\\n\") {\n\t\t\tcommentStr = chompRegexp.ReplaceAllString(commentStr, \"\")\n\t\t\tlog.Debugf(\"chompRegexp [%v]\", commentStr)\n\t\t\tcommentStr = xmlEncodeMultilineCommentRegex.ReplaceAllString(commentStr, \"$1$2\")\n\t\t\tlog.Debugf(\"processed multiline [%v]\", commentStr)\n\t\t\t// if the first line is non blank, add a space\n\t\t\tif commentStr[0] != '\\n' && commentStr[0] != ' ' {\n\t\t\t\tcommentStr = \" \" + commentStr","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/encoder_xml.go#L183-L219","documentation":"doEncode dispatches on node Kind (mapping, sequence, scalar) and has no case for anything else — an AliasNode or other kind reaching it fails with `unsupported type %v` reporting the node tag. It means an alias (or non-standard node) is nested inside a map/array being XML-encoded.","triggerScenarios":"Encoding to XML a document where a value inside a map or array is an unresolved AliasNode (kind AliasNode), e.g. `a: &x 1\\nb: *x` encoded without the alias being resolved by evaluation.","commonSituations":"YAML with anchors converted straight to XML; alias-bearing documents whose aliases were not dereferenced because the expression did not touch them; embedding yqlib with hand-built trees.","solutions":["Dereference aliases first: yq -o json in.yaml | yq -o xml, or use an expression that materializes values.","Inline the anchored value instead of using an alias in the source.","Normalize the tree before encoding in embedded usage (resolve alias nodes to their targets).","Patch doEncode to add an AliasNode case delegating to the alias target."],"exampleFix":"// before\nbase: &b {x: 1}\nderived: *b\n// after\nbase: &b {x: 1}\nderived: {x: 1}","handlingStrategy":"type-guard","validationCode":"yq '[.. | select(kind == \"alias\")] | length' in.yaml  # must be 0 for -o xml","typeGuard":"// Go\nfunc hasAliasDeep(n *yqlib.CandidateNode) bool {\n    if n.Kind == yqlib.AliasNode { return true }\n    for _, c := range n.Content { if hasAliasDeep(c) { return true } }\n    return false\n}","tryCatchPattern":"// Go\nif err := enc.Encode(w, node); err != nil {\n    if strings.Contains(err.Error(), \"unsupported type\") {\n        node = dereferenceAliases(node) // JSON round-trip\n    }\n}","preventionTips":["Dereference anchors before XML encoding","Inline alias values in source documents","Test conversions on anchor-heavy YAML explicitly"],"tags":["xml","encoder","yaml-aliases","unsupported-node-kind"],"backgroundTag":"xml-unsupported-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"}