{"record":{"id":"88fa328e1484a534","repo":"mikefarah/yq","slug":"aliases-are-not-supported-in-toml","errorCode":null,"errorMessage":"aliases are not supported in TOML","messagePattern":"aliases are not supported in TOML","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/encoder_toml.go","lineNumber":335,"sourceCode":"\t\t\t// Write the element value\n\t\t\tvar itemStr string\n\t\t\tswitch it.Kind {\n\t\t\tcase ScalarNode:\n\t\t\t\titemStr = te.formatScalar(it)\n\t\t\tcase SequenceNode:\n\t\t\t\tnested, err := te.sequenceToInlineArray(it)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\titemStr = nested\n\t\t\tcase MappingNode:\n\t\t\t\tinline, err := te.mappingToInlineTable(it)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\titemStr = inline\n\t\t\tcase AliasNode:\n\t\t\t\treturn fmt.Errorf(\"aliases are not supported in TOML\")\n\t\t\tdefault:\n\t\t\t\treturn fmt.Errorf(\"unsupported array item kind: %v\", it.Kind)\n\t\t\t}\n\n\t\t\t// Always add trailing comma in multiline arrays\n\t\t\titemStr += \",\"\n\n\t\t\tif _, err := w.Write([]byte(\"  \" + itemStr + \"\\n\")); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\t// Add blank line between elements (except after the last one)\n\t\t\tif i < len(seq.Content)-1 {\n\t\t\t\tif _, err := w.Write([]byte(\"\\n\")); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t}\n\t\t}","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/encoder_toml.go#L317-L353","documentation":"The TOML encoder cannot serialize YAML alias nodes (anchors referenced with *). TOML has no concept of anchors/aliases, so when writeArrayAttribute encounters an AliasNode as an array element it fails instead of silently dereferencing. Note that normal yq evaluation usually resolves aliases, so this typically surfaces when aliases reach the encoder unresolved.","triggerScenarios":"Running yq with -o toml (or to_toml) on a document where a sequence element is a YAML alias node (e.g. `a: &x 1\\nb: [*x]`) that was not dereferenced during evaluation, hitting the multiline-array branch of writeArrayAttribute.","commonSituations":"Piping YAML with anchors/merge keys straight to TOML output; building arrays programmatically with alias nodes from load/select on anchored values; scripts converting anchor-heavy YAML config to TOML.","solutions":["Use evalV3 semantics or ensure aliases are resolved: apply an operator that materializes values, e.g. yq -o toml '(.[] | select(tag == \"!!alias\"))' is not needed — instead restructure the expression so alias nodes are dereferenced (e.g. pipe through [... (...)] copies).","Explode the anchor manually: replace the alias with its value before encoding (copy the anchored value inline).","If the input format allows, drop anchors/aliases in a pre-pass: yq -o json first (JSON has no aliases so they are dereferenced), then convert to TOML.","Report/patch: handle AliasNode by resolving it.Value in writeArrayAttribute."],"exampleFix":"// before\nyq -o toml '.' anchored.yaml   # errors on alias elements\n// after\nyq -o json '.' anchored.yaml | yq -o toml '.'   # aliases resolved via JSON round-trip","handlingStrategy":"type-guard","validationCode":"yq 'any(.[]; tag == \"!!alias\" or kind == \"alias\")' in.yaml  # nonzero/skip encode if true","typeGuard":"// Go (yqlib)\nfunc hasAlias(seq *yqlib.CandidateNode) bool {\n    for _, it := range seq.Content {\n        if it.Kind == yqlib.AliasNode { return true }\n    }\n    return false\n}","tryCatchPattern":"// Go\nout, err := yqlib.NewYqFormatter(...).EncodeTOML(node)\nif err != nil && strings.Contains(err.Error(), \"aliases are not supported in TOML\") {\n    // dereference aliases (JSON round-trip) and retry\n}","preventionTips":["Route YAML with anchors through JSON before TOML output","Avoid anchors/aliases in documents destined for TOML","Test conversions with a grep for '&' and '*' anchors in source YAML"],"tags":["toml","encoder","yaml-aliases","unsupported-node-kind"],"backgroundTag":"toml-alias-unsupported","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"}