siyuan-note/siyuan · error

unregisterCapability requires 1 argument: name

Error message

unregisterCapability requires 1 argument: name

What it means

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.

Solutions

  1. Pass the exact registered name string: unregisterCapability("myplugin_tool")
  2. Store capability names at registration time and reuse them at teardown
  3. Guard cleanup code so it only runs when a name is available

Example fix

// before
plugin.unregisterCapability();
// after
plugin.unregisterCapability("myplugin_search_notes");
Defensive patterns

Strategy: validation

Validate before calling

const args = [toolName]; if (args.length < 1 || typeof args[0] !== "string") { throw new Error("unregisterCapability needs a name string"); }

Type guard

const canUnregister = (n) => arguments.length >= 1 && typeof n === "string";

Try / catch

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; }

Prevention

When it happens

Trigger: unregisterCapability() with no arguments, e.g. a cleanup hook that dropped the name variable, or forwarding code that filters out the argument.

Common situations: 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.

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


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/26f4c8748086d59f. Report an issue: GitHub.

Appendix: source

Thrown at kernel/plugin/api_agent.go:218

		if runErr != nil {
			logging.LogErrorf("[plugin:%s] siyuan.agent.registerCapability worker run: %v", p.Name, runErr)
			if rejectErr := reject(rt.NewGoError(runErr)); rejectErr != nil {
				logging.LogErrorf("[plugin:%s] siyuan.agent.registerCapability reject on run error: %v", p.Name, rejectErr)
			}
		}

		return rt.ToValue(promise)
	})))

	// siyuan.agent.unregisterCapability(name) 返回 Promise<void>。
	lo.Must0(agentAPI.Set("unregisterCapability", rt.ToValue(func(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
		promise, resolve, reject := rt.NewPromise()

		var argErr error
		var toolName string

		if len(call.Arguments) < 1 {
			argErr = fmt.Errorf("unregisterCapability requires 1 argument: name")
		} else if s := call.Argument(0); goja.IsString(s) {
			toolName = s.String()
		} else {
			argErr = fmt.Errorf("first argument must be a tool name string")
		}

		if argErr != nil {
			_ = reject(rt.NewGoError(argErr))
			return rt.ToValue(promise)
		}

		runErr := p.worker.Run(func(rt *goja.Runtime) (result any, err error) {
			p.unregisterAgentCapability(toolName)
			return
		}, func(workerRT *goja.Runtime, result any, err error) {
			if lo.IsNil(err) {
				if resolveErr := resolve(result); resolveErr != nil {
					logging.LogErrorf("[plugin:%s] siyuan.agent.unregisterCapability resolve: %v", p.Name, resolveErr)

View on GitHub (pinned to 9f775e8a12)