{"record":{"id":"e8f632efee3bfd51","repo":"flipped-aurora/gin-vue-admin","slug":"package","errorCode":null,"errorMessage":"Package为空!","messagePattern":"Package为空!","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/model/system/request/sys_auto_code.go","lineNumber":200,"sourceCode":"\t\tif r.GvaModel {\n\t\t\tr.PrimaryField = &AutoCodeField{\n\t\t\t\tFieldName:    \"ID\",\n\t\t\t\tFieldType:    \"uint\",\n\t\t\t\tFieldDesc:    \"ID\",\n\t\t\t\tFieldJson:    \"ID\",\n\t\t\t\tDataTypeLong: \"20\",\n\t\t\t\tComment:      \"主键ID\",\n\t\t\t\tColumnName:   \"id\",\n\t\t\t}\n\t\t}\n\t} // GvaModel\n\t{\n\t\tif r.IsAdd && r.PrimaryField == nil {\n\t\t\tr.PrimaryField = new(AutoCodeField)\n\t\t}\n\t} // 新增字段模式下不关注主键\n\tif r.Package == \"\" {\n\t\treturn errors.New(\"Package为空!\")\n\t} // 增加判断：Package不为空\n\tpackages := []rune(r.Package)\n\tif len(packages) > 0 {\n\t\tif packages[0] >= 97 && packages[0] <= 122 {\n\t\t\tpackages[0] = packages[0] - 32\n\t\t}\n\t\tr.PackageT = string(packages)\n\t} // PackageT 是 Package 的首字母大写\n\treturn nil\n}\n\nfunc (r *AutoCode) History() SysAutoHistoryCreate {\n\tbytes, _ := json.Marshal(r)\n\treturn SysAutoHistoryCreate{\n\t\tTable:        r.TableName,\n\t\tPackage:      r.Package,\n\t\tRequest:      string(bytes),\n\t\tStructName:   r.StructName,","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/model/system/request/sys_auto_code.go#L182-L218","documentation":"Pretreatment validates an AutoCode (code generator) request before Preview/Create. The Package field names the Go package the generated code belongs to and must be non-empty; this check runs before the value is normalized (first letter uppercased etc.). An empty Package means the generator cannot place the generated files, so it short-circuits with this error.","triggerScenarios":"Calling Preview or Create with AutoCodeGenReq.Package == \"\" — e.g. the frontend form never filled the package (module) field, or the field was lost when constructing the request programmatically.","commonSituations":"Hand-built JSON payloads for the code generator omitting `package`; form submit with module/package select left empty; automated scripts calling the autocode API directly; template/config migration dropping the package field.","solutions":["Set the package field in the code-generation form (select/create a package/module) before previewing or creating","Include package in the API payload: {\"package\":\"myapp\", ...}","Check that frontend form binding actually maps the package input into the request object","Trim whitespace — an all-whitespace value still fails via other validations; provide a real identifier"],"exampleFix":"// before\nawait createAutoCode({ tableName: 'users', fields })\n// after\nawait createAutoCode({ tableName: 'users', package: 'example', fields })","handlingStrategy":"validation","validationCode":"// client-side, before calling preview/create\nif (!req.package || !String(req.package).trim()) {\n  throw new Error('package is required for code generation')\n}","typeGuard":"function hasPackage(r) {\n  return typeof r?.package === 'string' && r.package.trim().length > 0\n}","tryCatchPattern":"try {\n  await createAutoCode(req)\n} catch (e) {\n  if (String(e.message).includes('Package为空')) {\n    formRef.value.validateField('package') // highlight the missing field\n  } else { throw e }\n}","preventionTips":["Mark the package field required in the generator form with form-level validation","Always include package in hand-built API payloads","Add a backend request-binding test asserting package presence"],"tags":["autocode","validation","code-generator"],"backgroundTag":"missing-required-field","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}