mikefarah/yq · error

lua encoder NYI -- %s

Error message

lua encoder NYI -- %s

What it means

The Lua encoder hits a CandidateNode whose YAML tag it has no case for inside a scalar-tag switch, so it returns 'lua encoder NYI' (not yet implemented) naming the tag. It is a guard against emitting invalid Lua for exotic/unknown tags (custom types, timestamps, merge keys, etc.).

Source

Thrown at pkg/yqlib/encoder_lua.go:306

				if err != nil {
					return err
				}
				return writeString(writer, fmt.Sprintf("%d", octalValue))
			}
			return writeString(writer, strings.ToLower(node.Value))
		case "!!float":
			switch strings.ToLower(node.Value) {
			case ".inf", "+.inf":
				return writeString(writer, "(1/0)")
			case "-.inf":
				return writeString(writer, "(-1/0)")
			case ".nan":
				return writeString(writer, "(0/0)")
			default:
				return writeString(writer, node.Value)
			}
		default:
			return fmt.Errorf("lua encoder NYI -- %s", node.Tag)
		}
	default:
		return fmt.Errorf("lua encoder NYI -- %s", node.Tag)
	}
}

func (le *luaEncoder) encodeTopLevel(writer io.Writer, node *CandidateNode) error {
	err := writeString(writer, le.docPrefix)
	if err != nil {
		return err
	}
	err = le.encodeAny(writer, node)
	if err != nil {
		return err
	}
	return writeString(writer, le.docSuffix)
}

View on GitHub (pinned to 8b5af0694b)

Solutions

  1. Strip or normalize the unsupported tag first: `yq -o lua '(.[] | select(tag != "!!str")) |= (. tag="!!str")'` or pipe the whole doc through `... |= tostring` where appropriate.
  2. Use `tag` operator to inspect which tag triggers it, then `.|="tag value"` to replace it with a plain scalar.
  3. Encode to a supported format (yaml/json) if the document relies on custom tags.
  4. If the tag is common and genuinely unsupported, file/patch an upstream case in encoder_lua.go.

Example fix

# before
yq -o lua '.' data.yaml   # data has a !!binary value

# after
yq -o lua '(.[] | select(tag == "!!binary")) |= (. value="binary data")' data.yaml
Defensive patterns

Strategy: type-guard

Validate before calling

yq '[.. | tag] | unique' file.yaml   # inspect all tags before -o lua

Type guard

guard() { yq -e 'all(tag == "!!str" or tag == "!!int" or tag == "!!float" or tag == "!!bool" or tag == "!!null" or tag == "!!map" or tag == "!!seq")' "$1"; }

Try / catch

if ! yq -o lua '.' file.yaml > out.lua 2>err.txt; then echo "Lua encode failed: $(cat err.txt)"; fi

Prevention

When it happens

Trigger: Encoding a document containing a node with an unhandled tag (e.g. `!!timestamp`-derived custom type, `!!binary`, or a custom `!!set` style tag) through encodeAny when the node is not one of the handled scalar kinds/tags; reached from encodeArray, encodeMap, or encodeTopLevel.

Common situations: Converting YAML with custom type tags (e.g. `!!python/object` style tags, `!!binary` blobs) to Lua; documents produced by other tools that attach custom tags; round-tripping YAML with `!!merge` keys.

Related errors


AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05). Data as JSON: /api/errors/bd6c774d71cbea29. Report an issue: GitHub.