siyuan-note/siyuan · error
injectEvent
Error message
injectEvent: %v
What it means
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.
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
Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
try {
await loadPlugin(p);
} catch (e) {
if (String(e.message).startsWith('injectEvent:')) {
console.error('Event API failed to install:', e.message);
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/ba5e2809c0604275.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/plugin/api_event.go:31
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package plugin
import (
"fmt"
"github.com/dop251/goja"
"github.com/samber/lo"
"github.com/siyuan-note/logging"
)
// injectEvent adds siyuan.event to the goja context.
func injectEvent(p *KernelPlugin, rt *goja.Runtime, siyuan *goja.Object) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("injectEvent: %v", r)
}
}()
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 == "" {View on GitHub (pinned to 9f775e8a12)