siyuan-note/siyuan · error
method name and function required
Error message
method name and function required
What it means
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.
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
Example fix
// before
siyuan.rpc.bind('myMethod');
// after
siyuan.rpc.bind('myMethod', (params) => { return {ok: true}; }); Defensive patterns
Strategy: validation
Validate before calling
function assertBindArgs(args) {
if (!Array.isArray(args) || args.length < 2) {
throw new TypeError('rpc.bind requires (name, fn) — two arguments');
}
if (typeof args[0] !== 'string' || typeof args[1] !== 'function') {
throw new TypeError('rpc.bind requires a string name and a function');
}
return args;
}
// call site: siyuan.rpc.bind(...assertBindArgs([name, handler])) Type guard
function isBindable(name, fn) {
return typeof name === 'string' && name.length > 0 && typeof fn === 'function';
} Try / catch
try {
siyuan.rpc.bind(name, handler);
} catch (e) {
if (String(e.message).includes('method name and function required')) {
console.error('rpc.bind called with missing name or handler:', {name, handler: typeof handler});
}
throw e;
} Prevention
- 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
When it happens
Trigger: Calling rpc.bind('myMethod') without the function, or bind() with no arguments; spreading an argument array shorter than two.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- first argument must be method name string
- assetPath is required for analyze
- cannot remove storage root
- config.actionEffects contains an empty action
- invalid id field: must be string, number, null or omitted
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/e8f2fb720edf36c2.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/plugin/api_rpc.go:46
// injectRpc adds siyuan.rpc method for RPC method registration.
func injectRpc(p *KernelPlugin, rt *goja.Runtime, siyuan *goja.Object) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("injectRpc: %v", r)
}
}()
rpc := rt.NewObject()
lo.Must0(rpc.Set("bind", rt.ToValue(func(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
promise, resolve, reject := rt.NewPromise()
var argErr error
var name string
var method goja.Callable
var descriptions []string
if len(call.Arguments) < 2 {
argErr = fmt.Errorf("method name and function required")
} else {
nameArg := call.Argument(0)
methodArg := call.Argument(1)
descArgs := call.Arguments[2:]
if goja.IsString(nameArg) {
name = nameArg.String()
} else {
argErr = fmt.Errorf("first argument must be method name string")
}
if argErr == nil {
if methodJs, ok := goja.AssertFunction(methodArg); ok {
method = methodJs
} else {
argErr = fmt.Errorf("second argument must be a function")
}
}
if argErr == nil {
descriptions = make([]string, len(descArgs))View on GitHub (pinned to 9f775e8a12)