{"record":{"id":"a6b3135b2a909dc3","repo":"xpzouying/xiaohongshu-mcp","slug":"s-a6b313","errorCode":null,"errorMessage":"不支持的可见范围: %s，支持: 公开可见、仅自己可见、仅互关好友可见","messagePattern":"不支持的可见范围: (.+?)，支持: 公开可见、仅自己可见、仅互关好友可见","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/publish.go","lineNumber":885,"sourceCode":"\n// hasExactClass 检查 class 字符串是否包含指定的完整类名（单词边界匹配）\nfunc hasExactClass(classStr, className string) bool {\n\tpattern := `\\b` + regexp.QuoteMeta(className) + `\\b`\n\tmatched, _ := regexp.MatchString(pattern, classStr)\n\treturn matched\n}\n\n// setVisibility 设置可见范围\n// 支持: \"公开可见\"(默认), \"仅自己可见\", \"仅互关好友可见\"\nfunc setVisibility(page *rod.Page, visibility string) error {\n\tif visibility == \"\" || visibility == \"公开可见\" {\n\t\tslog.Info(\"可见范围使用默认：公开可见\")\n\t\treturn nil\n\t}\n\n\tsupported := map[string]bool{\"仅自己可见\": true, \"仅互关好友可见\": true}\n\tif !supported[visibility] {\n\t\treturn errors.Errorf(\"不支持的可见范围: %s，支持: 公开可见、仅自己可见、仅互关好友可见\", visibility)\n\t}\n\n\tdropdown, err := page.Element(\"div.permission-card-wrapper div.d-select-content\")\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"查找可见范围下拉框失败\")\n\t}\n\tif err := humanize.Click(dropdown); err != nil {\n\t\treturn errors.Wrap(err, \"点击可见范围下拉框失败\")\n\t}\n\ttime.Sleep(500 * time.Millisecond)\n\n\t// 在弹窗中查找并点击目标选项\n\topts, err := page.Elements(\"div.d-options-wrapper div.d-grid-item div.custom-option\")\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"查找可见范围选项失败\")\n\t}\n\tfor _, opt := range opts {\n\t\ttext, err := opt.Text()","sourceCodeStart":867,"sourceCodeEnd":903,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/publish.go#L867-L903","documentation":"setVisibility rejects a visibility value not in its supported set before touching the UI. Only 公开可见 (default, empty string), 仅自己可见, and 仅互关好友可见 are supported; anything else returns this errors.Errorf immediately. It is a client-side input validation, not a browser failure.","triggerScenarios":"Calling submitPublish/submitPublishVideo (or setVisibility) with visibility like \"私密\", \"好友可见\", or any non-empty string outside the supported map and not equal to \"公开可见\".","commonSituations":"Config files or CLI flags passing English values ('public','private'), typos, or newer Xiaohongshu options not yet mapped in the library.","solutions":["Use exactly one of: \"\" / \"公开可见\", \"仅自己可见\", \"仅互关好友可见\".","Trim whitespace and normalize the input before calling.","Add the new value to the supported map only after verifying the option exists in the UI.","Validate visibility in your own config loading layer before invoking publish."],"exampleFix":"// before\nvisibility = \"private\"\nerr := submitPublish(page, ..., visibility)\n// after\nvisibility = \"仅自己可见\" // 或 \"公开可见\" / \"仅互关好友可见\"\nerr := submitPublish(page, ..., visibility)","handlingStrategy":"validation","validationCode":"var allowed = map[string]bool{\"\": true, \"公开可见\": true, \"仅自己可见\": true, \"仅互关好友可见\": true}\nif !allowed[visibility] { return fmt.Errorf(\"非法 visibility: %q\", visibility) }","typeGuard":"func validVisibility(v string) bool { return v == \"\" || v == \"公开可见\" || v == \"仅自己可见\" || v == \"仅互关好友可见\" }","tryCatchPattern":"if err := submitPublish(page, post, visibility); err != nil {\n    if strings.Contains(err.Error(), \"不支持的可见范围\") {\n        return submitPublish(page, post, \"\") // 回退默认公开\n    }\n    return err\n}","preventionTips":["Validate visibility at config-load time","Use a fixed enum/const set, not free-form strings","Trim and normalize user input before passing through"],"tags":["validation","input-error","xhs-publish"],"backgroundTag":"unsupported-enum-value","analyzedSha":"332d196854a9eac0d2b8c2c0e3d0cc43139d724c","analyzedAt":"2026-09-05T22:22:55.988Z","contentChangedAt":"2026-09-05T22:22:55.988Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}