{"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/251596fc0de2f9528c00c224252fd073a99973f4/kernel/plugin/api_agent.go#L200-L236","documentation":"Thrown by siyuan.agent.unregisterCapability when called with zero arguments (len(call.Arguments) < 1). The API requires the capability name to know which tool to unregister from the agent's capability registry.","triggerScenarios":"Calling siyuan.agent.unregisterCapability() with no arguments. The plugin may have destructured or computed the name and it was undefined/absent.","commonSituations":"Plugin cleanup code calls unregisterCapability in a loop but the name variable is empty; teardown logic runs before names are populated; copy-paste omission.","solutions":["Pass the capability name string that was used during registerCapability","Store registered capability names and pass them to unregisterCapability on teardown"],"exampleFix":"// before\nawait siyuan.agent.unregisterCapability();\n\n// after\nawait siyuan.agent.unregisterCapability('myTool');","handlingStrategy":"validation","validationCode":"if (arguments.length < 1 || typeof arguments[0] !== 'string') {\n  throw new Error('unregisterCapability requires a name string');\n}\nawait siyuan.agent.unregisterCapability(name);","typeGuard":null,"tryCatchPattern":"try {\n  await siyuan.agent.unregisterCapability(name);\n} catch (e) {\n  console.error('unregisterCapability failed:', e.message);\n}","preventionTips":["Always pass the capability name that was used during registration","Track registered names in an array for clean teardown"],"tags":["plugin","agent","capability","validation","javascript"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}