siyuan-note/siyuan · error
topic required
Error message
topic required
What it means
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.
Source
Thrown at kernel/plugin/api_event.go:50
}
}()
event := rt.NewObject()
lo.Must0(event.Set("handler", goja.Null()))
lo.Must0(event.Set("emit", rt.ToValue(func(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
promise, resolve, reject := rt.NewPromise()
var argErr error
var topic string
var eventData any
if len(call.Arguments) < 2 {
argErr = fmt.Errorf("topic and event required")
} else {
topic = call.Argument(0).String()
if topic == "" {
argErr = fmt.Errorf("topic required")
} else {
eventData = call.Argument(1).Export()
}
}
runErr := p.worker.Run(func(rt *goja.Runtime) (result any, err error) {
if argErr != nil {
err = argErr
return
}
p.bus.Publish(topic, eventData)
return
}, func(rt *goja.Runtime, result any, err error) {
if lo.IsNil(err) {
if resolveErr := resolve(result); resolveErr != nil {
logging.LogErrorf("[plugin:%s] siyuan.event.emit resolve: %v", p.Name, resolveErr)
}
} else {View on GitHub (pinned to 251596fc0d)
Solutions
- Provide a non-empty topic string.
- Default the topic: const t = topic || 'default-topic'.
Example fix
// before
siyuan.event.emit('', data);
// after
siyuan.event.emit('my-event', data); Defensive patterns
Strategy: validation
Validate before calling
const t = (typeof topic === 'string' && topic.length) ? topic : 'default'; siyuan.event.emit(t, data);
Type guard
const isTopic = (v) => typeof v === 'string' && v.length > 0;
Prevention
- Validate topics before emit.
- Use constants for topic names.
When it happens
Trigger: Calling emit('', data), or emit(someVar, data) where someVar evaluated to ''.
Common situations: Topic built from optional config that was unset, or a typo/trim leaving an empty string.
Related errors
- topic and event required
- Failed to update agent session permission
- Agent capability name and description are required
- invalid frontend capability ID: %s
- frontend capability description is required: %s
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/7538f9f961daf412.
Report an issue: GitHub.