{"record":{"id":"ad04c077b733de2e","repo":"flipped-aurora/gin-vue-admin","slug":"llmauto-mode","errorCode":null,"errorMessage":"llmAuto 缺少 mode 参数","messagePattern":"llmAuto 缺少 mode 参数","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_llm.go","lineNumber":98,"sourceCode":"\t\t},\n\t\tnil,\n\t\tpayload,\n\t\t-1, // 不设置 client.Timeout，SSE 流的生命周期由 ctx 控制\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"调用上游大模型流式服务失败: %w\", err)\n\t}\n\treturn res, nil\n}\n\nfunc buildLLMAutoPath(llm common.JSONMap) (string, error) {\n\tif global.GVA_CONFIG.AutoCode.AiPath == \"\" {\n\t\treturn \"\", errors.New(\"请先前往插件市场个人中心获取 AiPath 并填写到 config.yaml 中\")\n\t}\n\n\tmode := strings.TrimSpace(fmt.Sprintf(\"%v\", llm[\"mode\"]))\n\tif mode == \"\" {\n\t\treturn \"\", errors.New(\"llmAuto 缺少 mode 参数\")\n\t}\n\n\treturn strings.ReplaceAll(global.GVA_CONFIG.AutoCode.AiPath, \"{FUNC}\", mode), nil\n}\n\nfunc cloneLLMAutoJSONMap(src common.JSONMap) common.JSONMap {\n\tdst := make(common.JSONMap, len(src))\n\tfor key, value := range src {\n\t\tdst[key] = value\n\t}\n\treturn dst\n}\n\nfunc previewResponseBody(body []byte) string {\n\ttext := strings.TrimSpace(string(body))\n\ttext = strings.ReplaceAll(text, \"\\r\", \" \")\n\ttext = strings.ReplaceAll(text, \"\\n\", \" \")\n\ttext = strings.Join(strings.Fields(text), \" \")","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_llm.go#L80-L116","documentation":"After validating AiPath, buildLLMAutoPath() reads llm[\"mode\"] from the request's JSONMap, trims and stringifies it. If mode is empty it returns 'llmAuto 缺少 mode 参数', because {FUNC} in the AiPath cannot be substituted without a mode.","triggerScenarios":"Calling LLMAuto or LLMAutoStream with a request body whose llm object omits \"mode\", sets it to null, or sets it to an empty/whitespace-only string.","commonSituations":"Frontend form not sending the selected AI generation mode (file/table/package auto paths); older clients calling a renamed field; hand-crafted API requests in tests/Postman missing the llm.mode key; mode cleared by a UI reset before submit.","solutions":["Include a non-empty llm.mode in the request body (the AI auto-generation mode selected in the UI).","Inspect the outgoing JSON payload in devtools to confirm the mode field is present under llm.","Update the frontend caller to always send mode before invoking the LLMAuto endpoint.","If mode is dynamic, validate it client-side and block submission when empty."],"exampleFix":"// before\nconst payload = { llm: { prompt } } // mode missing\n// after\nconst payload = { llm: { mode: selectedMode, prompt } } // e.g. mode: 'code'\nif (!selectedMode) return ElMessage.warning('请先选择生成模式')","handlingStrategy":"validation","validationCode":"// validate payload before calling the API\nif (!payload.llm || typeof payload.llm.mode !== 'string' || !payload.llm.mode.trim()) {\n  throw new Error('llm.mode is required (the AI generation mode)')\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await api.llmAuto(payload)\n} catch (err) {\n  if (String(err.msg || err).includes('缺少 mode')) {\n    // fix request: add llm.mode then retry once\n  } else {\n    throw err\n  }\n}","preventionTips":["Always send llm.mode from the UI's selected generation mode","Add client-side required-field checks before submit","Keep frontend field names in sync with the backend JSONMap keys","Cover the LLMAuto call in e2e tests with a real mode value"],"tags":["autocode","llm","validation","missing-parameter"],"backgroundTag":"missing-required-parameter","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}