Jguer/yay · error
expected boolean, got
Error message
expected boolean, got %s
What it means
assign maps a Lua value onto a reflect.Bool struct field and requires an LBool. Other Lua types cannot be interpreted as a Go bool, so it returns an error naming the actual Lua type. The wrapping layer prefixes it with yay.opt.<key>.
Solutions
- Use Lua's real booleans in init.lua: true or false, unquoted
- If you need conditional logic, compute the boolean in Lua: yay.opt.rebuild = (os.getenv("CI") ~= nil)
- Confirm the Go field is bool; if the setting is genuinely tri-state/string, change the struct field type
Example fix
// before (init.lua) yay.opt.rebuild = "yes" // after yay.opt.rebuild = true
Defensive patterns
Strategy: validation
Validate before calling
-- init.lua assert(type(yay.opt.rebuild) == "boolean", "yay.opt.rebuild must be true or false")
Try / catch
if err != nil && strings.Contains(err.Error(), "expected boolean") {
fixBoolOptionInInitLua()
} Prevention
- Use unquoted true/false only
- Do not use "yes"/"no" or 1/0 for Go bool fields
- Compute booleans with expressions like (x ~= nil)
When it happens
Trigger: An init.lua option bound to a Go bool field is set to a string or number, e.g. yay.opt.rebuild = "yes" or yay.opt.rebuild = 1.
Common situations: Using strings 'true'/'yes' for booleans (a YAML/JSON habit); using 0/1 numeric flags; Lua expression evaluating to nil instead of a boolean.
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/472a777346e8a5fc.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/settings/lua/lua.go:170
}
}
return index
}
func assign(field reflect.Value, val lua.LValue) error {
switch field.Kind() {
case reflect.String:
s, ok := val.(lua.LString)
if !ok {
return fmt.Errorf("expected string, got %s", val.Type())
}
field.SetString(string(s))
case reflect.Bool:
b, ok := val.(lua.LBool)
if !ok {
return fmt.Errorf("expected boolean, got %s", val.Type())
}
field.SetBool(bool(b))
case reflect.Int, reflect.Int64:
n, ok := val.(lua.LNumber)
if !ok {
return fmt.Errorf("expected number, got %s", val.Type())
}
field.SetInt(int64(n))
case reflect.Slice:
return assignStructSlice(field, val)
default:
return fmt.Errorf("unsupported field kind %s", field.Kind())
}
return nil
}View on GitHub (pinned to 328f4b4939)