Jguer/yay · error

entry keys must be strings, got

Error message

entry keys must be strings, got %s

What it means

assignStructSlice iterates the outer yay.opt table and requires each key to be an LString, because the key becomes the entry's name stored in the struct's lua:"name" field. Numeric array-style keys or other key types abort with 'entry keys must be strings, got <type>'.

Solutions

  1. Rewrite the value as a name-keyed map: yay.opt.ignored = { pkg1 = {}, pkg2 = {} }
  2. If building in Lua, index by explicit string names instead of table.insert
  3. Ensure no bare numeric keys are mixed into the entry table

Example fix

// before (init.lua)
yay.opt.ignored = { "linux-headers" }
// after
yay.opt.ignored = { ["linux-headers"] = {} }
Defensive patterns

Strategy: validation

Validate before calling

-- init.lua
for k in pairs(yay.opt.ignored or {}) do
    assert(type(k) == "string", "ignored entries must be keyed by package name strings")
end

Try / catch

if err != nil && strings.Contains(err.Error(), "entry keys must be strings") {
    convertListToNameKeyedTableInInitLua()
}

Prevention

When it happens

Trigger: Using an array-style (1-based) list in init.lua for a struct-slice option, e.g. yay.opt.ignored = {"pkg1","pkg2"}, or mixing numeric keys into the name-keyed table.

Common situations: Writing {"a","b"} out of list habit instead of a map keyed by entry name; building the table programmatically with table.insert, which produces numeric keys.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of Jguer/yay@328f4b4939 (2026-09-07). Data as JSON: /api/errors/b0760255860ac753. Report an issue: GitHub.

Appendix: source

Thrown at pkg/settings/lua/lua.go:233

	type namedElem struct {
		name string
		elem reflect.Value
	}

	var (
		entries  []namedElem
		firstErr error
	)

	tbl.ForEach(func(k, entry lua.LValue) {
		if firstErr != nil {
			return
		}

		name, ok := k.(lua.LString)
		if !ok {
			firstErr = fmt.Errorf("entry keys must be strings, got %s", k.Type())
			return
		}

		entryTbl, ok := entry.(*lua.LTable)
		if !ok {
			firstErr = fmt.Errorf("entry %q must be a table, got %s", string(name), entry.Type())
			return
		}

		elem := reflect.New(elemType).Elem()
		if hasName {
			elem.Field(nameIdx).SetString(string(name))
		}

		if err := assignStructFields(elem, entryTbl, fieldIndex); err != nil {
			firstErr = fmt.Errorf("entry %q: %w", string(name), err)
			return
		}

View on GitHub (pinned to 328f4b4939)