siyuan-note/siyuan · error

injectEvent: %v

Error message

injectEvent: %v

What it means

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.

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 8641553a1f)

Solutions

  1. Restart the kernel/plugin host so a fresh goja runtime is used
  2. Update the kernel — this is an internal setup fault, not user-fixable in plugin code
  3. Check kernel logs for the wrapped panic detail (%v) to identify the failing registration
  4. Disable recently installed plugins to isolate a plugin that corrupts the worker
Defensive patterns

Strategy: try-catch

Try / catch

try { startPluginRuntime(); } catch (e) { if (String(e).startsWith("injectEvent:")) { restartKernelPluginHost(); } else { throw e; } }

Prevention

When it happens

Trigger: 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.

Common situations: Kernel-side regression in API setup; plugin worker terminated concurrently with injection; malformed plugin bootstrap sequence causing injection on a dead runtime.

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@8641553a1f (2026-09-11). Data as JSON: /api/errors/ba5e2809c0604275. Report an issue: GitHub.