xpzouying/xiaohongshu-mcp · error
视频不能为空
Error message
视频不能为空
What it means
PublishVideo 入口的参数校验守卫:调用方传入的 PublishVideoContent.VideoPath 为空字符串,说明上游构造内容时漏填了视频路径,属于必填项缺失,非运行时故障。
Source
Thrown at xiaohongshu/publish_video.go:57
if err := pp.WaitDOMStable(time.Second, 0.1); err != nil {
logrus.Warnf("等待 DOM 稳定出现问题: %v,继续尝试", err)
}
time.Sleep(1 * time.Second)
if err := mustClickPublishTab(pp, "上传视频"); err != nil {
return nil, errors.Wrap(err, "切换到上传视频失败")
}
time.Sleep(1 * time.Second)
return &PublishAction{page: pp}, nil
}
// PublishVideo 上传视频并提交
func (p *PublishAction) PublishVideo(ctx context.Context, content PublishVideoContent) error {
if content.VideoPath == "" {
return errors.New("视频不能为空")
}
// 重设超时:.Context(ctx) 会替换掉 NewPublishVideoAction 里 Timeout(300s) 的 deadline
page := p.page.Context(ctx).Timeout(300 * time.Second)
if err := uploadVideo(page, content.VideoPath); err != nil {
return errors.Wrap(err, "小红书上传视频失败")
}
if err := submitPublishVideo(ctx, page, content.Title, content.Content, content.Tags, content.ScheduleTime, content.Visibility, content.Products); err != nil {
return errors.Wrap(err, "小红书发布失败")
}
return nil
}
// uploadVideo 上传单个本地视频
func uploadVideo(page *rod.Page, videoPath string) error {
pp := page.Timeout(5 * time.Minute) // 视频处理耗时更长View on GitHub (pinned to 332d196854)
Solutions
- 调用前检查 content.VideoPath != ""
- 确保上层正确读取并传递视频文件路径
- 同时用 os.Stat 校验文件真实存在
Example fix
// before
_ = action.PublishVideo(ctx, PublishVideoContent{Title: title})
// after
if videoPath == "" { return errors.New("video path required") }
_ = action.PublishVideo(ctx, PublishVideoContent{VideoPath: videoPath, Title: title}) Defensive patterns
Strategy: validation
Validate before calling
func validateVideoContent(c PublishVideoContent) error {
if c.VideoPath == "" { return errors.New("VideoPath 不能为空") }
if _, err := os.Stat(c.VideoPath); err != nil { return fmt.Errorf("视频文件不可读: %w", err) }
return nil
}
// 调用前: if err := validateVideoContent(content); err != nil { return err } Prevention
- 构造 PublishVideoContent 后先做非空与文件存在性校验
- 从配置读取路径时打印日志确认非空
- 为 VideoPath 提供默认值或启动时校验配置完整性
When it happens
Trigger: 调用 PublishVideo(ctx, PublishVideoContent{...}) 时未设置 VideoPath 字段(漏填、变量名拼错、上层逻辑未给值)。
Common situations: 从配置文件/命令行读视频路径失败后仍继续调用;结构体零值直接传入;路径校验函数只检查了文件存在性而未检查非空。
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- no valid images found
- 标题长度超过限制
- 定时发布时间格式错误,请使用 ISO8601 格式: %v
- 定时发布时间必须至少在1小时后,当前设置: %s,最早可选: %s
- 定时发布时间不能超过14天,当前设置: %s,最晚可选: %s
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/2fc89d0bc4c21b07.
Report an issue: GitHub.