{"record":{"id":"ba5e2809c0604275","repo":"siyuan-note/siyuan","slug":"injectevent-v","errorCode":null,"errorMessage":"injectEvent: %v","messagePattern":"injectEvent: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_event.go","lineNumber":31,"sourceCode":"//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\npackage plugin\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/dop251/goja\"\n\t\"github.com/samber/lo\"\n\t\"github.com/siyuan-note/logging\"\n)\n\n// injectEvent adds siyuan.event to the goja context.\nfunc injectEvent(p *KernelPlugin, rt *goja.Runtime, siyuan *goja.Object) (err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"injectEvent: %v\", r)\n\t\t}\n\t}()\n\n\tevent := rt.NewObject()\n\n\tlo.Must0(event.Set(\"handler\", goja.Null()))\n\n\tlo.Must0(event.Set(\"emit\", rt.ToValue(func(call goja.FunctionCall, rt *goja.Runtime) goja.Value {\n\t\tpromise, resolve, reject := rt.NewPromise()\n\n\t\tvar argErr error\n\t\tvar topic string\n\t\tvar eventData any\n\t\tif len(call.Arguments) < 2 {\n\t\t\targErr = fmt.Errorf(\"topic and event required\")\n\t\t} else {\n\t\t\ttopic = call.Argument(0).String()\n\t\t\tif topic == \"\" {","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/api_event.go#L13-L49","documentation":"injectEvent registers the siyuan.event object into the plugin's goja runtime during plugin bootstrap. Any Go panic during that registration (object creation, method binding, failed native Set calls) is recovered and returned as this error. It means the event API could not be installed and plugin initialization for that API failed.","triggerScenarios":"A panic inside rt.NewObject(), event.Set(...), or the handler bridging setup while the kernel initializes the plugin runtime — goja internal failures or injector programming errors.","commonSituations":"Kernel-side defects during plugin bootstrap; encountered when loading a plugin whose runtime initialization hits an unexpected state; not caused by plugin JS, which has not run yet.","solutions":["Read the wrapped %v detail for the root cause and report it to the SiYuan maintainers with the plugin name","Update the kernel to the latest version","Disable other plugins to rule out interference during runtime initialization","Retry loading the plugin to rule out a transient failure"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  await loadPlugin(p);\n} catch (e) {\n  if (String(e.message).startsWith('injectEvent:')) {\n    console.error('Event API failed to install:', e.message);\n  }\n}","preventionTips":["Keep the kernel binary current; these are kernel-internal bootstrap failures","Guard plugin code with feature checks (typeof siyuan.event !== 'undefined') in case injection failed","Collect the full error text when filing a bug report"],"tags":["goja","plugin-init","panic","event"],"backgroundTag":"internal-invariant-violation","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}