{"record":{"id":"26f4c8748086d59f","repo":"siyuan-note/siyuan","slug":"unregistercapability-requires-1-argument-name","errorCode":null,"errorMessage":"unregisterCapability requires 1 argument: name","messagePattern":"unregisterCapability requires 1 argument: name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_agent.go","lineNumber":218,"sourceCode":"\t\tif runErr != nil {\n\t\t\tlogging.LogErrorf(\"[plugin:%s] siyuan.agent.registerCapability worker run: %v\", p.Name, runErr)\n\t\t\tif rejectErr := reject(rt.NewGoError(runErr)); rejectErr != nil {\n\t\t\t\tlogging.LogErrorf(\"[plugin:%s] siyuan.agent.registerCapability reject on run error: %v\", p.Name, rejectErr)\n\t\t\t}\n\t\t}\n\n\t\treturn rt.ToValue(promise)\n\t})))\n\n\t// siyuan.agent.unregisterCapability(name) 返回 Promise<void>。\n\tlo.Must0(agentAPI.Set(\"unregisterCapability\", 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 toolName string\n\n\t\tif len(call.Arguments) < 1 {\n\t\t\targErr = fmt.Errorf(\"unregisterCapability requires 1 argument: name\")\n\t\t} else if s := call.Argument(0); goja.IsString(s) {\n\t\t\ttoolName = s.String()\n\t\t} else {\n\t\t\targErr = fmt.Errorf(\"first argument must be a tool name string\")\n\t\t}\n\n\t\tif argErr != nil {\n\t\t\t_ = reject(rt.NewGoError(argErr))\n\t\t\treturn rt.ToValue(promise)\n\t\t}\n\n\t\trunErr := p.worker.Run(func(rt *goja.Runtime) (result any, err error) {\n\t\t\tp.unregisterAgentCapability(toolName)\n\t\t\treturn\n\t\t}, func(workerRT *goja.Runtime, result any, err error) {\n\t\t\tif lo.IsNil(err) {\n\t\t\t\tif resolveErr := resolve(result); resolveErr != nil {\n\t\t\t\t\tlogging.LogErrorf(\"[plugin:%s] siyuan.agent.unregisterCapability resolve: %v\", p.Name, resolveErr)","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/api_agent.go#L200-L236","documentation":"unregisterCapability() removes a previously registered agent capability by name and requires exactly one argument: the tool name string. This error is raised when the call is made with zero arguments; without a name the kernel cannot identify which capability to remove.","triggerScenarios":"unregisterCapability() with no arguments, e.g. a cleanup hook that dropped the name variable, or forwarding code that filters out the argument.","commonSituations":"Plugin teardown/unload logic where the stored name was lost; refactored loops that call unregister without forwarding the parameter; copying the signature from another no-argument API.","solutions":["Pass the exact registered name string: unregisterCapability(\"myplugin_tool\")","Store capability names at registration time and reuse them at teardown","Guard cleanup code so it only runs when a name is available"],"exampleFix":"// before\nplugin.unregisterCapability();\n// after\nplugin.unregisterCapability(\"myplugin_search_notes\");","handlingStrategy":"validation","validationCode":"const args = [toolName]; if (args.length < 1 || typeof args[0] !== \"string\") { throw new Error(\"unregisterCapability needs a name string\"); }","typeGuard":"const canUnregister = (n) => arguments.length >= 1 && typeof n === \"string\";","tryCatchPattern":"try { await plugin.unregisterCapability(name); } catch (e) { if (String(e).includes(\"unregisterCapability requires 1 argument\")) { console.warn(\"Skip unregister: no name available\"); return; } throw e; }","preventionTips":["Store capability names at registration and reuse them at teardown","Guard cleanup paths so they never run without a name","Use constants for capability names instead of inlined strings"],"tags":["plugin-api","argument-count","agent-capability"],"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"}