{"record":{"id":"28df77a4590e9eb3","repo":"flipped-aurora/gin-vue-admin","slug":"params-v","errorCode":null,"errorMessage":"解析 params 参数失败: %v","messagePattern":"解析 params 参数失败: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/sys_export_template.go","lineNumber":135,"sourceCode":"\tif err != nil {\n\t\treturn\n\t}\n\n\tif limit != 0 {\n\t\tdb = db.Limit(limit).Offset(offset)\n\t}\n\n\terr = db.Find(&sysExportTemplates).Error\n\treturn sysExportTemplates, total, err\n}\n\n// ExportExcel 导出Excel\n// Author [piexlmax](https://github.com/piexlmax)\nfunc (sysExportTemplateService *SysExportTemplateService) ExportExcel(ctx context.Context, templateID string, values url.Values) (file *bytes.Buffer, name string, err error) {\n\tvar params = values.Get(\"params\")\n\tparamsValues, err := url.ParseQuery(params)\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"解析 params 参数失败: %v\", err)\n\t}\n\tvar template system.SysExportTemplate\n\terr = global.GVA_DB.WithContext(ctx).Preload(\"Conditions\").Preload(\"JoinTemplate\").First(&template, \"template_id = ?\", templateID).Error\n\tif err != nil {\n\t\treturn nil, \"\", err\n\t}\n\tf := excelize.NewFile()\n\tdefer func() {\n\t\tif err := f.Close(); err != nil {\n\t\t\tfmt.Println(err)\n\t\t}\n\t}()\n\t// Create a new sheet.\n\tindex, err := f.NewSheet(\"Sheet1\")\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/sys_export_template.go#L117-L153","documentation":"ExportExcel parses the 'params' query value as a URL query string (url.ParseQuery). If the params value is empty or not valid form-encoded data (e.g. missing '=' separators, bad percent-encoding), it returns this wrapped error.","triggerScenarios":"GET/POST export with params=<malformed> such as params=conditions (no key=value pair) or params=a%zz=1 (invalid percent-encoding); params omitted entirely yields empty string which ParseQuery accepts, so it fails only on truly invalid syntax.","commonSituations":"Frontend building params manually without encodeURIComponent; proxies or log sanitizers stripping or mangling query encoding; copy-pasted URLs with truncated params.","solutions":["Encode params correctly, e.g. params=encodeURIComponent(' conditions=a&dictType=b ')","Ensure every pair has form key=value separated by &","Check the request actually reaches the service with params intact (not stripped by middleware)","Log the raw params value at the handler layer to confirm what is received"],"exampleFix":"// before\nconst qs = `conditions=${conditions}&dictType=${dictType}` // unencoded, may break\n// after\nconst qs = new URLSearchParams({ conditions, dictType }).toString()\nawait exportExcel(templateId, `params=${encodeURIComponent(qs)}`)","handlingStrategy":"validation","validationCode":"const inner = new URLSearchParams(payload).toString()\nconst params = new URLSearchParams({ params: inner }).toString()\n// params guaranteed valid form-encoding","typeGuard":null,"tryCatchPattern":"try {\n  await exportExcel(templateId, params)\n} catch (e) {\n  if (e.message.includes('解析 params')) {\n    ElMessage.error('导出参数格式错误')\n  }\n}","preventionTips":["Centralize export param building in one util","Round-trip test params: parse what you build"],"tags":["go","url-parsing","export","query-params"],"backgroundTag":"query-string-parse-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}