{"record":{"id":"da14ff0791c197d7","repo":"Jguer/yay","slug":"s-s-w","errorCode":null,"errorMessage":"%s %s: %w","messagePattern":"%s %s: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/settings/lua/autocmd.go","lineNumber":203,"sourceCode":"\treturn e.runAUREvent(EventAURPreInstall, event)\n}\n\nfunc (e *Engine) RunAURPostDownload(event *AURPreInstallEvent) error {\n\treturn e.runAUREvent(EventAURPostDownload, event)\n}\n\nfunc (e *Engine) runAUREvent(eventName string, event *AURPreInstallEvent) error {\n\tif !e.HasAutocmd(eventName) {\n\t\treturn nil\n\t}\n\n\tfor _, autocmd := range e.autocmds[eventName] {\n\t\tif err := e.L.CallByParam(glua.P{\n\t\t\tFn:      autocmd.callback,\n\t\t\tNRet:    0,\n\t\t\tProtect: true,\n\t\t}, e.aurEventTable(eventName, event)); err != nil {\n\t\t\treturn fmt.Errorf(\"%s %s: %w\", eventName, event.Base, wrapLuaErr(err))\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (e *Engine) RunUpgradeSelect(event *UpgradeSelectEvent) (UpgradeSelectResult, error) {\n\tvar result UpgradeSelectResult\n\tif !e.HasAutocmd(EventUpgradeSelect) {\n\t\treturn result, nil\n\t}\n\n\tvalidExcludes := mapset.NewThreadUnsafeSetWithSize[string](len(event.Upgrades))\n\tfor i := range event.Upgrades {\n\t\tvalidExcludes.Add(event.Upgrades[i].Name)\n\t}\n\n\tseenExcludes := mapset.NewThreadUnsafeSet[string]()","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/Jguer/yay/blob/328f4b4939fb35f38c2f7c7ce3b8638a839bafa5/pkg/settings/lua/autocmd.go#L185-L221","documentation":"runAUREvent invokes each registered Lua autocmd callback for an event via gopher-lua's protected call; if the Lua function errors or panics inside Lua, the failure is wrapped as '<eventName> <pkgBase>: <lua error>'. The Go side cannot proceed with the event handling because a user script failed. wrapLuaErr strips the gopher-lua wrapper so the underlying script message is surfaced.","triggerScenarios":"An autocmd registered for an AUR event (e.g. via createAutocmd) whose callback raises a Lua runtime error (calling nil, bad index, abort()) while processing an event for package event.Base.","commonSituations":"User Lua config script has a typo or references an undefined helper; the callback expects a different event table shape after a yay version change; abort() used deliberately in the script to stop operations.","solutions":["Read the wrapped Lua error message to find the failing line in your autocmd callback","Fix the nil reference/typo in the Lua callback","Update the script if event table fields changed after an upgrade","Temporarily remove the autocmd registration to confirm the script is the cause","Use abort() intentionally if you want to halt the operation cleanly"],"exampleFix":"-- before\nautocmd('PreInstall', function(e) install_extra(e.base) end)\n-- after\nautocmd('PreInstall', function(e)\n  if type(e.base) ~= 'string' then abort('missing base') end\n  install_extra(e.base)\nend)","handlingStrategy":"try-catch","validationCode":"-- in your Lua config, sanity-check the callback before registering\nlocal ok, err = pcall(function() assert(type(myHook) == 'function') end)\nif not ok then error('bad autocmd callback: ' .. tostring(err)) end","typeGuard":null,"tryCatchPattern":"if err := engine.RunAURHook(eventName, event); err != nil {\n\tlog.Warnf(\"autocmd failed, continuing without it: %v\", err)\n}","preventionTips":["Wrap risky hook bodies in pcall inside Lua","Test scripts with a mock event table before relying on them","Keep hooks minimal; put complex logic in required modules you can unit test","Re-test hooks after every yay upgrade"],"tags":["lua","autocmd","scripting","callback"],"backgroundTag":"script-callback-runtime-error","analyzedSha":"328f4b4939fb35f38c2f7c7ce3b8638a839bafa5","analyzedAt":"2026-09-07T16:45:12.608Z","contentChangedAt":"2026-09-07T16:45:12.608Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}