{"record":{"id":"7538f9f961daf412","repo":"siyuan-note/siyuan","slug":"topic-required","errorCode":null,"errorMessage":"topic required","messagePattern":"topic required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_event.go","lineNumber":50,"sourceCode":"\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) {\n\t\t\t\tif resolveErr := resolve(result); resolveErr != nil {\n\t\t\t\t\tlogging.LogErrorf(\"[plugin:%s] siyuan.event.emit resolve: %v\", p.Name, resolveErr)\n\t\t\t\t}\n\t\t\t} else {","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/plugin/api_event.go#L32-L68","documentation":"Thrown by siyuan.event.emit when the topic argument is an empty string. emit treats '' as no topic and refuses to publish, since bus subscribers key on the topic string.","triggerScenarios":"Calling emit('', data), or emit(someVar, data) where someVar evaluated to ''.","commonSituations":"Topic built from optional config that was unset, or a typo/trim leaving an empty string.","solutions":["Provide a non-empty topic string.","Default the topic: const t = topic || 'default-topic'."],"exampleFix":"// before\nsiyuan.event.emit('', data);\n// after\nsiyuan.event.emit('my-event', data);","handlingStrategy":"validation","validationCode":"const t = (typeof topic === 'string' && topic.length) ? topic : 'default';\nsiyuan.event.emit(t, data);","typeGuard":"const isTopic = (v) => typeof v === 'string' && v.length > 0;","tryCatchPattern":null,"preventionTips":["Validate topics before emit.","Use constants for topic names."],"tags":["event-bus","emit","validation","topic"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}