{"record":{"id":"bb3aa2e0e83b1ca9","repo":"xpzouying/xiaohongshu-mcp","slug":"no-valid-images-found","errorCode":null,"errorMessage":"no valid images found","messagePattern":"no valid images found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/downloader/processor.go","lineNumber":45,"sourceCode":"\tlocalPaths := make([]string, 0, len(images))\n\n\t// 按顺序处理每张图片\n\tfor _, image := range images {\n\t\tif IsImageURL(image) {\n\t\t\t// URL图片：立即下载，失败直接返回错误\n\t\t\tlocalPath, err := p.downloader.DownloadImage(image)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"下载图片失败 %s: %w\", image, err)\n\t\t\t}\n\t\t\tlocalPaths = append(localPaths, localPath)\n\t\t} else {\n\t\t\t// 本地路径直接使用\n\t\t\tlocalPaths = append(localPaths, image)\n\t\t}\n\t}\n\n\tif len(localPaths) == 0 {\n\t\treturn nil, fmt.Errorf(\"no valid images found\")\n\t}\n\n\treturn localPaths, nil\n}\n","sourceCodeStart":27,"sourceCodeEnd":50,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/pkg/downloader/processor.go#L27-L50","documentation":"ProcessImages returns this error when, after iterating the input image list, no image was resolved to a local path — either the input was empty or every entry failed validation (neither a valid image URL nor a usable local path entry). It guards downstream publish flows from receiving an empty image set.","triggerScenarios":"Calling ProcessImages with an empty images slice, or a list where all entries are URLs that were skipped/failed validation, producing zero localPaths.","commonSituations":"Passing req.Images as an empty array from the client; passing strings that are neither valid URLs nor existing local paths (e.g. data URIs or relative paths misinterpreted); field renamed upstream so images arrive empty.","solutions":["Ensure req.Images contains at least one valid image URL or existing local file path","Validate the input list length and each entry with IsImageURL / os.Stat before calling ProcessImages","If the image is optional, skip the publish-images flow entirely when the list is empty instead of calling ProcessImages"],"exampleFix":"// before\nlocalPaths, err := processor.ProcessImages(ctx, req.Images) // panics err on empty\n// after\nif len(req.Images) == 0 { return errors.New(\"at least one image is required\") }\nlocalPaths, err := processor.ProcessImages(ctx, req.Images)","handlingStrategy":"validation","validationCode":"if len(images) == 0 {\n    return errors.New(\"images: at least one image url or local path required\")\n}\nvalid := 0\nfor _, img := range images {\n    if IsImageURL(img) || fileExists(img) { valid++ }\n}\nif valid == 0 { return errors.New(\"images: no valid entries\") }","typeGuard":"func hasProcessableImage(images []string) bool {\n    for _, img := range images {\n        if IsImageURL(img) { return true }\n        if fi, err := os.Stat(img); err == nil && !fi.IsDir() { return true }\n    }\n    return false\n}","tryCatchPattern":"localPaths, err := processor.ProcessImages(ctx, images)\nif err != nil && err.Error() == \"no valid images found\" {\n    return fmt.Errorf(\"publish aborted: images payload empty or invalid: %w\", err)\n}","preventionTips":["Reject empty Images arrays at the API boundary (HTTP handler level)","Normalize input: strip data-URIs and whitespace entries that validate to nothing","Log the original request payload when this error fires to spot upstream serialization bugs"],"tags":["go","validation","input","downloader"],"backgroundTag":"empty-required-input","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"}