{"record":{"id":"27def267e94f05af","repo":"github/copilot-sdk","slug":"invalid-s-tool-name-must-not-be-empty","errorCode":null,"errorMessage":"invalid %s tool name: must not be empty","messagePattern":"invalid (.+?) tool name: must not be empty","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/toolset.go","lineNumber":89,"sourceCode":"\n// AddMCP adds an MCP tool pattern. Matches tools advertised by any configured\n// MCP server.\nfunc (s *ToolSet) AddMCP(toolName string) *ToolSet {\n\tvalidateToolName(\"mcp\", toolName)\n\ts.items = append(s.items, \"mcp:\"+toolName)\n\treturn s\n}\n\n// ToSlice returns a defensive copy of the accumulated filter strings.\nfunc (s *ToolSet) ToSlice() []string {\n\tout := make([]string, len(s.items))\n\tcopy(out, s.items)\n\treturn out\n}\n\nfunc validateToolName(kind, name string) {\n\tif name == \"\" {\n\t\tpanic(fmt.Sprintf(\"invalid %s tool name: must not be empty\", kind))\n\t}\n\tif name == \"*\" {\n\t\treturn\n\t}\n\tif !toolNameRegex.MatchString(name) {\n\t\tpanic(fmt.Sprintf(\n\t\t\t\"invalid %s tool name %q: tool names must match /^[a-zA-Z0-9_-]+$/ or be the wildcard %q\",\n\t\t\tkind, name, \"*\"))\n\t}\n}\n\n// BuiltInToolsIsolated lists built-in tools that operate only within the\n// bounds of a single session — no host filesystem access outside the session,\n// no cross-session state, no host environment access, no network. Safe to\n// enable in [ModeEmpty] scenarios (e.g. multi-tenant servers) without leaking\n// host capabilities.\n//\n// Contract: tools in this set MUST NOT be extended (even behind options or","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/toolset.go#L71-L107","documentation":"validateToolName rejects empty tool names passed to the ToolSet builders. AddBuiltIn, AddCustom, and AddMCP all funnel through this validator, and an empty name would produce an un-addressable tool entry, so the library panics immediately with the tool kind in the message. Wildcard \"*\" and regex-valid names pass through.","triggerScenarios":"Calling AddBuiltIn(\"\"), AddCustom(\"\") or AddMCP(\"\") — typically when the name comes from a variable/config value that is an empty string, or from iterating a map with missing keys yielding \"\".","commonSituations":"Config file or environment value for a tool name missing so the lookup returns \"\"; a struct field not set before building the ToolSet; string splitting producing empty entries (e.g. strings.Split(\"a,,b\", \",\")).","solutions":["Ensure the name variable is populated before calling the Add method; fail early in your own config loading if empty.","Filter out empty strings when building names from a delimited list or map iteration.","Pass a concrete valid tool name ([a-zA-Z0-9_-]+ or \"*\") instead of an empty string."],"exampleFix":"// before\nfor _, n := range strings.Split(spec.Tools, \",\") {\n    ts.AddBuiltIn(n) // panics on \"\"\n}\n\n// after\nfor _, n := range strings.Split(spec.Tools, \",\") {\n    if n == \"\" { continue }\n    ts.AddBuiltIn(n)\n}","handlingStrategy":"validation","validationCode":"func addableToolName(n string) bool { return n != \"\" }","typeGuard":"func nonEmpty(s string) bool { return s != \"\" }","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        if s, ok := r.(string); ok && strings.Contains(s, \"tool name: must not be empty\") {\n            log.Fatalf(\"tool registration failed: %s\", s)\n        }\n        panic(r)\n    }\n}()","preventionTips":["Validate tool names at config-load time and reject empty entries early.","Skip or error on empty items when splitting delimited tool lists.","Check map lookups for ok before using the returned name string."],"tags":["go","panic","validation","toolset","empty-value"],"backgroundTag":"empty-required-field","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}