xpzouying/xiaohongshu-mcp · error

no valid images found

Error message

no valid images found

What it means

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.

Source

Thrown at pkg/downloader/processor.go:45

	localPaths := make([]string, 0, len(images))

	// 按顺序处理每张图片
	for _, image := range images {
		if IsImageURL(image) {
			// URL图片:立即下载,失败直接返回错误
			localPath, err := p.downloader.DownloadImage(image)
			if err != nil {
				return nil, fmt.Errorf("下载图片失败 %s: %w", image, err)
			}
			localPaths = append(localPaths, localPath)
		} else {
			// 本地路径直接使用
			localPaths = append(localPaths, image)
		}
	}

	if len(localPaths) == 0 {
		return nil, fmt.Errorf("no valid images found")
	}

	return localPaths, nil
}

View on GitHub (pinned to 332d196854)

Solutions

  1. Ensure req.Images contains at least one valid image URL or existing local file path
  2. Validate the input list length and each entry with IsImageURL / os.Stat before calling ProcessImages
  3. If the image is optional, skip the publish-images flow entirely when the list is empty instead of calling ProcessImages

Example fix

// before
localPaths, err := processor.ProcessImages(ctx, req.Images) // panics err on empty
// after
if len(req.Images) == 0 { return errors.New("at least one image is required") }
localPaths, err := processor.ProcessImages(ctx, req.Images)
Defensive patterns

Strategy: validation

Validate before calling

if len(images) == 0 {
    return errors.New("images: at least one image url or local path required")
}
valid := 0
for _, img := range images {
    if IsImageURL(img) || fileExists(img) { valid++ }
}
if valid == 0 { return errors.New("images: no valid entries") }

Type guard

func hasProcessableImage(images []string) bool {
    for _, img := range images {
        if IsImageURL(img) { return true }
        if fi, err := os.Stat(img); err == nil && !fi.IsDir() { return true }
    }
    return false
}

Try / catch

localPaths, err := processor.ProcessImages(ctx, images)
if err != nil && err.Error() == "no valid images found" {
    return fmt.Errorf("publish aborted: images payload empty or invalid: %w", err)
}

Prevention

When it happens

Trigger: Calling ProcessImages with an empty images slice, or a list where all entries are URLs that were skipped/failed validation, producing zero localPaths.

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

Related errors


AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05). Data as JSON: /api/errors/bb3aa2e0e83b1ca9. Report an issue: GitHub.