{"record":{"id":"69a38cd11df39c0f","repo":"flipped-aurora/gin-vue-admin","slug":"api-q-path-method-path","errorCode":null,"errorMessage":"无法解析API项 %q,期望 \"/path\" 或 \"METHOD /path\"","messagePattern":"无法解析API项 %q,期望 \"/path\" 或 \"METHOD /path\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/role_api_batch_assigner.go","lineNumber":209,"sourceCode":"\t\tif _, ok := seen[key]; ok {\n\t\t\tcontinue\n\t\t}\n\t\tseen[key] = struct{}{}\n\t\tdeduped = append(deduped, item)\n\t}\n\treturn deduped, nil\n}\n\n// parseAPIItemString 解析\"METHOD /path\"或\"/path\"形式的单条API,方法缺省为POST\nfunc parseAPIItemString(s string) (path, method string, err error) {\n\tfields := strings.Fields(strings.TrimSpace(s))\n\tswitch len(fields) {\n\tcase 1:\n\t\treturn fields[0], \"\", nil\n\tcase 2:\n\t\treturn fields[1], fields[0], nil\n\tdefault:\n\t\treturn \"\", \"\", fmt.Errorf(\"无法解析API项 %q,期望 \\\"/path\\\" 或 \\\"METHOD /path\\\"\", s)\n\t}\n}\n","sourceCodeStart":191,"sourceCodeEnd":212,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/role_api_batch_assigner.go#L191-L212","documentation":"The role-API batch assigner parses each API item string expecting either a bare path `/path` or a `METHOD /path` pair. A string that splits into more than two whitespace-separated fields cannot be interpreted, so parsing aborts with this error naming the offending item.","triggerScenarios":"Passing an item like `POST /api/user extra` or an item containing accidental spaces/tabs/newlines to the APIs list of the batch assign tool.","commonSituations":"Copy-pasting a curl command line into the API item field; a stray comma converted to space; trailing comment after the path; Chinese full-width space mistaken as separator.","solutions":["Remove extra tokens so each item is exactly `/path` or `METHOD /path` (e.g. `POST /api/user`)","Check for full-width or invisible whitespace characters and replace them with nothing or a single ASCII space","Strip any comments or annotations from each item string","If method and path are supplied separately, use only the `/path` form and set the method elsewhere"],"exampleFix":"// before\nitems := []string{\"POST /api/user comment\", \"/api/user\"}\n// after\nitems := []string{\"POST /api/user\", \"/api/user\"}","handlingStrategy":"validation","validationCode":"func validAPIItem(s string) bool {\n    fields := strings.Fields(s)\n    if len(fields) == 1 {\n        return strings.HasPrefix(fields[0], \"/\")\n    }\n    if len(fields) == 2 {\n        return isHTTPMethod(fields[0]) && strings.HasPrefix(fields[1], \"/\")\n    }\n    return false\n}","typeGuard":"func normalizeAPIItem(s string) (string, error) {\n    s = strings.Join(strings.Fields(s), \" \")\n    if !validAPIItem(s) {\n        return \"\", fmt.Errorf(\"invalid API item %q\", s)\n    }\n    return s, nil\n}","tryCatchPattern":null,"preventionTips":["Pass items as `/path` or `METHOD /path` only","Strip comments and trailing whitespace from each item","Beware of full-width (U+3000) spaces when copying from Chinese docs","Split method and path fields programmatically rather than hand-formatting"],"tags":["mcp","parsing","input-validation"],"backgroundTag":"input-parse-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}