{"record":{"id":"e8f2fb720edf36c2","repo":"siyuan-note/siyuan","slug":"method-name-and-function-required","errorCode":null,"errorMessage":"method name and function required","messagePattern":"method name and function required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_rpc.go","lineNumber":46,"sourceCode":"// 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:]\n\t\t\tif goja.IsString(nameArg) {\n\t\t\t\tname = nameArg.String()\n\t\t\t} else {\n\t\t\t\targErr = fmt.Errorf(\"first argument must be method name string\")\n\t\t\t}\n\t\t\tif argErr == nil {\n\t\t\t\tif methodJs, ok := goja.AssertFunction(methodArg); ok {\n\t\t\t\t\tmethod = methodJs\n\t\t\t\t} else {\n\t\t\t\t\targErr = fmt.Errorf(\"second argument must be a function\")\n\t\t\t\t}\n\t\t\t}\n\t\t\tif argErr == nil {\n\t\t\t\tdescriptions = make([]string, len(descArgs))","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/api_rpc.go#L28-L64","documentation":"The siyuan.rpc.bind call requires at least two arguments: the RPC method name (string) and the implementing function. When fewer than two arguments are passed, the call is rejected with this error before any registration occurs. The promise/returned error surfaces to the plugin.","triggerScenarios":"Calling rpc.bind('myMethod') without the function, or bind() with no arguments; spreading an argument array shorter than two.","commonSituations":"Forgetting the handler after refactoring; passing the implementation via an object config form the API does not support; undefined variable silently dropped from the call.","solutions":["Pass both arguments: bind('methodName', handlerFunction)","Ensure the handler is an actual function value, not undefined","Check any spread call provides at least two elements","Verify the API signature in the plugin sample before calling"],"exampleFix":"// before\nsiyuan.rpc.bind('myMethod');\n// after\nsiyuan.rpc.bind('myMethod', (params) => { return {ok: true}; });","handlingStrategy":"validation","validationCode":"function assertBindArgs(args) {\n  if (!Array.isArray(args) || args.length < 2) {\n    throw new TypeError('rpc.bind requires (name, fn) — two arguments');\n  }\n  if (typeof args[0] !== 'string' || typeof args[1] !== 'function') {\n    throw new TypeError('rpc.bind requires a string name and a function');\n  }\n  return args;\n}\n// call site: siyuan.rpc.bind(...assertBindArgs([name, handler]))","typeGuard":"function isBindable(name, fn) {\n  return typeof name === 'string' && name.length > 0 && typeof fn === 'function';\n}","tryCatchPattern":"try {\n  siyuan.rpc.bind(name, handler);\n} catch (e) {\n  if (String(e.message).includes('method name and function required')) {\n    console.error('rpc.bind called with missing name or handler:', {name, handler: typeof handler});\n  }\n  throw e;\n}","preventionTips":["Always define the handler alongside the name in one place","Type-check handler variables (typeof fn === 'function') before binding","Avoid refactors that drop the handler argument from bind calls"],"tags":["plugin","rpc","missing-argument","validation"],"backgroundTag":"missing-required-argument","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"}