{"record":{"id":"ae388d4be596cc04","repo":"siyuan-note/siyuan","slug":"topic-and-event-required","errorCode":null,"errorMessage":"topic and event required","messagePattern":"topic and event required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_event.go","lineNumber":46,"sourceCode":"func 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 == \"\" {\n\t\t\t\targErr = fmt.Errorf(\"topic required\")\n\t\t\t} else {\n\t\t\t\teventData = call.Argument(1).Export()\n\t\t\t}\n\t\t}\n\n\t\trunErr := p.worker.Run(func(rt *goja.Runtime) (result any, err error) {\n\t\t\tif argErr != nil {\n\t\t\t\terr = argErr\n\t\t\t\treturn\n\t\t\t}\n\t\t\tp.bus.Publish(topic, eventData)\n\t\t\treturn\n\t\t}, func(rt *goja.Runtime, result any, err error) {\n\t\t\tif lo.IsNil(err) {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/plugin/api_event.go#L28-L64","documentation":"Thrown by siyuan.event.emit when fewer than 2 arguments are passed. emit(topic, data) publishes to the in-process event bus and requires both a topic and a payload.","triggerScenarios":"Calling emit('topic') with no payload, or emit() with no args. len(call.Arguments) < 2 triggers the error at api_event.go:45.","commonSituations":"Plugin emits a signal forgetting the data argument, or passes undefined explicitly expecting it to be tolerated.","solutions":["Pass both arguments: siyuan.event.emit('topic', data).","If you have no payload, pass null explicitly: emit('topic', null)."],"exampleFix":"// before\nsiyuan.event.emit('my-event');\n// after\nsiyuan.event.emit('my-event', { id: 1 });","handlingStrategy":"validation","validationCode":"if (arguments.length < 2) throw new Error('topic and data required');\nsiyuan.event.emit(topic, data);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a payload, even if null.","Wrap emit in a helper that enforces arity."],"tags":["event-bus","emit","validation","argument"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}