{"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/8641553a1f07374001902d3ce773285db1292b2d/kernel/plugin/api_event.go#L13-L49","documentation":"injectEvent installs the siyuan.event object into the plugin's goja runtime; this error wraps any panic occurring during that installation. A panic here usually means something went wrong while creating or registering the event API objects (e.g. the worker runtime is in a broken state or a required object failed to set). The error is reported to the plugin loader and typically aborts that injection step.","triggerScenarios":"Panic raised by rt.NewObject(), event.Set(...), or surrounding code while adding siyuan.event during plugin runtime bootstrap; a goja runtime that is shutting down or corrupted.","commonSituations":"Kernel-side regression in API setup; plugin worker terminated concurrently with injection; malformed plugin bootstrap sequence causing injection on a dead runtime.","solutions":["Restart the kernel/plugin host so a fresh goja runtime is used","Update the kernel — this is an internal setup fault, not user-fixable in plugin code","Check kernel logs for the wrapped panic detail (%v) to identify the failing registration","Disable recently installed plugins to isolate a plugin that corrupts the worker"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { startPluginRuntime(); } catch (e) { if (String(e).startsWith(\"injectEvent:\")) { restartKernelPluginHost(); } else { throw e; } }","preventionTips":["Keep kernel updated — this is an internal bootstrap fault","Avoid terminating the plugin worker during injection","Reproduce via kernel logs showing the wrapped panic value","Isolate misbehaving plugins that may corrupt the runtime"],"tags":["panic","plugin-api","goja","initialization"],"backgroundTag":"internal-invariant-violation","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}