{"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/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/api_rpc.go#L14-L50","documentation":"injectRpc registers the siyuan.rpc object (used to bind plugin-provided RPC methods) into the plugin's goja runtime. Any Go panic during registration is recovered and surfaced as this error, meaning RPC method registration could not be set up for the plugin.","triggerScenarios":"A panic inside rt.NewObject() or the rpc.Set('bind', ...) binding while the kernel initializes the plugin runtime.","commonSituations":"Kernel-side defects during plugin bootstrap; seen when a plugin that registers RPC methods fails to load.","solutions":["Inspect the wrapped %v detail and report it upstream 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 interference during initialization"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  await loadPlugin(p);\n} catch (e) {\n  if (String(e.message).startsWith('injectRpc:')) {\n    console.error('RPC API failed to install:', e.message);\n  }\n}","preventionTips":["Keep the kernel updated","Feature-check siyuan.rpc before binding methods","Include the wrapped panic detail in bug reports"],"tags":["goja","plugin-init","panic","rpc"],"backgroundTag":"internal-invariant-violation","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}