{"record":{"id":"df7cc7b4c683b3f3","repo":"siyuan-note/siyuan","slug":"injectrpc-v","errorCode":null,"errorMessage":"injectRpc: %v","messagePattern":"injectRpc: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_rpc.go","lineNumber":32,"sourceCode":"// 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\t\"github.com/siyuan-note/siyuan/kernel/util\"\n)\n\n// injectRpc adds siyuan.rpc method for RPC method registration.\nfunc injectRpc(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(\"injectRpc: %v\", r)\n\t\t}\n\t}()\n\n\trpc := rt.NewObject()\n\n\tlo.Must0(rpc.Set(\"bind\", 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 name string\n\t\tvar method goja.Callable\n\t\tvar descriptions []string\n\t\tif len(call.Arguments) < 2 {\n\t\t\targErr = fmt.Errorf(\"method name and function required\")\n\t\t} else {\n\t\t\tnameArg := call.Argument(0)\n\t\t\tmethodArg := call.Argument(1)\n\t\t\tdescArgs := call.Arguments[2:]","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/plugin/api_rpc.go#L14-L50","documentation":"injectRpc installs the siyuan.rpc object (bind/unbind/call) into the plugin's goja runtime. Any panic during this setup is recovered and wrapped as 'injectRpc: %v', aborting RPC registration for that plugin.","triggerScenarios":"A panic occurs while creating the rpc object or setting its bind method value in the goja runtime — e.g. corrupted runtime or nil pointers during object construction.","commonSituations":"Plugin bootstrap failure where the runtime is in an unexpected state; usually a kernel-side/internal issue rather than a plugin-author mistake.","solutions":["Inspect the wrapped %v message for the underlying panic cause","Ensure the goja runtime is healthy and not closed before injectRpc","Retry plugin load; if deterministic, debug kernel/plugin/api_rpc.go","Confirm lo.Must0 assertions on rpc.Set succeed (no duplicate/conflicting property definitions)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (typeof rt === \"undefined\" || rt === null) {\n    throw new Error(\"runtime unavailable before rpc injection\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    await registerRpc(plugin);\n} catch (e) {\n    if (String(e).startsWith(\"injectRpc:\")) {\n        console.error(\"rpc injection failed:\", e);\n    }\n}","preventionTips":["Ensure the runtime is not closed/corrupted during bootstrap","Retry plugin load once on transient runtime failures","Report deterministic panics to the kernel maintainers"],"tags":["goja","plugin","rpc","panic-recovery"],"backgroundTag":"module-init-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}