Jguer/yay · error
yay.opt.
Error message
yay.opt.%s: %w
What it means
When Apply iterates the Lua yay.opt table, a recognized key whose value cannot be assigned to the corresponding struct field (wrong Lua type for the field) is recorded as 'yay.opt.<key>: <cause>'. The error is collected rather than thrown immediately so Apply can report every bad option at once; Load then wraps these into the joined init.lua error.
Solutions
- Read the wrapped cause after 'yay.opt.<key>:' — it names the expected vs actual type
- Correct the Lua value's type in init.lua (remove quotes for numbers/booleans, use a table for slices)
- Check the struct field's Go type (and lua tag) to confirm the expected Lua type
Example fix
// before (init.lua) yay.opt.rebuild = "true" -- string, field is bool // after yay.opt.rebuild = true
Defensive patterns
Strategy: validation
Validate before calling
// Validate each yay.opt value type against the struct field before loading // e.g. for a bool field, require Lua true/false; for int, a bare number. -- init.lua self-check assert(type(yay.opt.rebuild) == "boolean", "rebuild must be boolean") assert(type(yay.opt.retries) == "number", "retries must be number")
Try / catch
_, errs := engine.Apply(&cfg)
for _, e := range errs {
var target error
if errors.As(e, &target) { log.Printf("bad option: %v", e) }
} Prevention
- Match Lua literal types to Go field kinds: no quotes for numbers/bools
- Keep a sample init.lua in docs showing the correct type per key
- Add Lua assert(type(...)) checks at the top of init.lua
When it happens
Trigger: A yay.opt entry in init.lua targets a known field but carries a value whose Lua type does not match the field kind handled by assign — e.g. a string assigned to a bool/int field, or a non-table assigned to a slice field.
Common situations: Quoting numbers (yay.opt.retries = "3" when the field is int); assigning a string where a boolean is expected; assigning a scalar to a struct-slice field.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- expected string, got
- expected boolean, got
- expected number, got
- expected table, got
- entry keys must be strings, got
AI-assisted analysis of Jguer/yay@328f4b4939 (2026-09-07).
Data as JSON: /api/errors/100f1650f0df1908.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/settings/lua/lua.go:86
if !ok {
return nil, nil
}
optTbl.ForEach(func(k, val lua.LValue) {
key, ok := k.(lua.LString)
if !ok {
return
}
fieldIdx, found := index[string(key)]
if !found {
unknown = append(unknown, string(key))
return
}
if err := assign(sv.Field(fieldIdx), val); err != nil {
errs = append(errs, fmt.Errorf("yay.opt.%s: %w", string(key), err))
}
})
return unknown, errs
}
func (e *Engine) optTable() (*lua.LTable, bool) {
yayTbl, ok := e.L.GetGlobal(globalName).(*lua.LTable)
if !ok {
return nil, false
}
optTbl, ok := e.L.GetField(yayTbl, optTableName).(*lua.LTable)
return optTbl, ok
}
// SetSearchDir makes require() resolve modules relative to dir (e.g.View on GitHub (pinned to 328f4b4939)