siyuan-note/siyuan · error
injectPlugin
Error message
injectPlugin: %v
What it means
injectPlugin installs the siyuan.plugin object (lifecycle hooks such as onload/onrunning) into the plugin's goja runtime. A panic during that installation is recovered and returned as this error, meaning the plugin lifecycle API could not be registered.
Solutions
- Read the wrapped %v detail and report it to the maintainers with the plugin name
- Update the kernel to the latest version
- Retry loading the plugin to rule out a transient failure
- Disable other plugins to rule out shared-state interference
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('injectPlugin:')) {
console.error('Plugin lifecycle API failed to install:', e.message);
}
} Prevention
- Keep the kernel binary current
- Feature-check siyuan.plugin before registering lifecycle hooks
- Capture the full error text for upstream bug reports
When it happens
Trigger: A panic inside rt.NewObject() or the lifecycle/property Set calls while the kernel bootstraps the plugin runtime.
Common situations: Kernel-side defects during plugin bootstrap; encountered at plugin load time, before plugin JS runs.
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
- injectEvent
- injectLogger
- injectRpc
- panic during lifecycle hook invocation
- globalThis.siyuan.plugin.lifecycle is not an object
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/5fcbc450d623809b.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/plugin/api_plugin.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/siyuan/kernel/bazaar"
)
// injectPlugin adds siyuan.plugin to the goja context.
func injectPlugin(p *KernelPlugin, rt *goja.Runtime, siyuan *goja.Object) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("injectPlugin: %v", r)
}
}()
lifecycle := rt.NewObject()
lo.Must0(lifecycle.Set("onload", goja.Null()))
lo.Must0(lifecycle.Set("onrunning", goja.Null()))
lo.Must0(lifecycle.Set("onunload", goja.Null()))
lo.Must0(ObjectSeal(rt, lifecycle))
plugin := rt.NewObject()
lo.Must0(plugin.Set("name", p.Name))
lo.Must0(plugin.Set("version", p.Version))
lo.Must0(plugin.Set("displayName", p.DisplayName))
lo.Must0(plugin.Set("platform", bazaar.GetCurrentBackend()))
lo.Must0(plugin.Set("i18n", p.I18n))
lo.Must0(plugin.Set("lifecycle", lifecycle))
lo.Must0(ObjectFreeze(rt, plugin))
View on GitHub (pinned to 9f775e8a12)