flipped-aurora/gin-vue-admin · error

解析generatedFiles失败: %v

Error message

解析generatedFiles失败: %v

What it means

The gva_review MCP tool accepts generatedFiles as a JSON-encoded string of a string array. Handle unmarshals it with json.Unmarshal and returns this error when the string is not valid JSON of []string (wrong quoting, objects instead of strings, etc.).

Source

Thrown at server/mcp/gva_review.go:88

		return nil, errors.New("参数错误:userRequirement 必须是字符串类型")
	}

	// 获取生成的文件列表
	generatedFilesData, ok := request.GetArguments()["generatedFiles"]
	if !ok {
		return nil, errors.New("参数错误:generatedFiles 必须提供")
	}

	generatedFilesStr, ok := generatedFilesData.(string)
	if !ok {
		return nil, errors.New("参数错误:generatedFiles 必须是JSON字符串")
	}

	// 解析JSON字符串为字符串数组
	var generatedFiles []string
	err := json.Unmarshal([]byte(generatedFilesStr), &generatedFiles)
	if err != nil {
		return nil, fmt.Errorf("解析generatedFiles失败: %v", err)
	}

	if len(generatedFiles) == 0 {
		return nil, errors.New("参数错误:generatedFiles 不能为空")
	}

	// 直接生成调整提示,不进行复杂分析
	adjustmentPrompt := g.generateAdjustmentPrompt(userRequirement, generatedFiles)

	// 构建简化的审查详情
	reviewDetails := fmt.Sprintf("📋 **代码审查报告**\n\n **用户原始需求:**\n%s\n\n **已生成文件数量:** %d\n\n **建议进行代码优化和完善**", userRequirement, len(generatedFiles))

	// 构建审查结果
	reviewResult := &ReviewResponse{
		Success:          true,
		Message:          "代码审查完成",
		AdjustmentPrompt: adjustmentPrompt,
		ReviewDetails:    reviewDetails,

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Ensure generatedFiles is a JSON array of strings serialized to a string: '["server/api/x.go","web/src/views/x.vue"]'
  2. Check for single quotes / trailing commas / HTML-escaped quotes in the payload
  3. Print and validate the argument with a JSON parser (JSON.parse / json.Valid) before calling the tool

Example fix

// before
generatedFiles: "server/api/a.go, web/src/views/a.vue"
// after
generatedFiles: "[\"server/api/a.go\", \"web/src/views/a.vue\"]"
Defensive patterns

Strategy: validation

Validate before calling

var files []string
if err := json.Unmarshal([]byte(generatedFilesStr), &files); err != nil {
  return fmt.Errorf("invalid generatedFiles JSON: %w", err)
}
if len(files) == 0 { return fmt.Errorf("generatedFiles empty") }

Type guard

func parseGeneratedFiles(s string) ([]string, bool) {
  var files []string
  if err := json.Unmarshal([]byte(s), &files); err != nil { return nil, false }
  return files, len(files) > 0
}

Try / catch

files, err := parseGeneratedFiles(raw)
if err != nil {
  // log raw and surface a 400-style argument error to the caller
  return nil, fmt.Errorf("generatedFiles argument invalid: %w", err)
}

Prevention

When it happens

Trigger: Calling the review tool with generatedFiles='["a.go", "b.go"]' malformed, e.g. single quotes, unescaped quotes, an object array, or a plain comma-separated string.

Common situations: LLM/tool client double-encodes or forgets to JSON-encode the array; passing a Go/JS array directly instead of its JSON string representation; trailing commas in hand-written JSON.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/ef2be68810ded7f2. Report an issue: GitHub.