{"record":{"id":"1a8b2bcde0dae006","repo":"flipped-aurora/gin-vue-admin","slug":"packagename-1a8b2b","errorCode":null,"errorMessage":"PackageName不能为空!","messagePattern":"PackageName不能为空!","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/service/system/auto_code_package.go","lineNumber":37,"sourceCode":"\t\"github.com/pkg/errors\"\n\t\"gorm.io/gorm\"\n)\n\nvar AutoCodePackage = new(autoCodePackage)\n\ntype autoCodePackage struct{}\n\n// Create 创建包信息\n// @author: [piexlmax](https://github.com/piexlmax)\n// @author: [SliverHorn](https://github.com/SliverHorn)\nfunc (s *autoCodePackage) Create(ctx context.Context, info *request.SysAutoCodePackageCreate) error {\n\tswitch {\n\tcase info.Template == \"\":\n\t\treturn errors.New(\"模板不能为空!\")\n\tcase info.Template == \"page\":\n\t\treturn errors.New(\"page为表单生成器!\")\n\tcase info.PackageName == \"\":\n\t\treturn errors.New(\"PackageName不能为空!\")\n\tcase token.IsKeyword(info.PackageName):\n\t\treturn errors.Errorf(\"%s为go的关键字!\", info.PackageName)\n\tcase info.Template == \"package\":\n\t\tif info.PackageName == \"system\" || info.PackageName == \"example\" {\n\t\t\treturn errors.New(\"不能使用已保留的package name\")\n\t\t}\n\tdefault:\n\t\tbreak\n\t}\n\tif !errors.Is(global.GVA_DB.Where(\"package_name = ? and template = ?\", info.PackageName, info.Template).First(&model.SysAutoCodePackage{}).Error, gorm.ErrRecordNotFound) {\n\t\treturn errors.New(\"存在相同PackageName\")\n\t}\n\tcreate := info.Create()\n\treturn global.GVA_DB.WithContext(ctx).Transaction(func(tx *gorm.DB) error {\n\t\terr := tx.Create(&create).Error\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"创建失败!\")\n\t\t}","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_package.go#L19-L55","documentation":"When creating an auto-code package via sysAutoCodePackage.Create, the request is validated by a switch chain. This error fires when info.PackageName is empty: a package without a name cannot become a Go module/package name for generated code. It is a pure input-validation guard thrown before any DB access.","triggerScenarios":"Calling the create-package API (POST autoCode/package) with a body whose packageName field is omitted or empty string, e.g. {\"template\":\"package\"} without packageName.","commonSituations":"Frontend form submitting before the package-name input is filled; API scripts/curl calls missing the field; code generators invoking the service directly with a zero-valued request struct.","solutions":["Set packageName in the request body to a valid non-empty Go package name (lowercase letters/digits, e.g. 'myapp').","On the frontend, validate the package name field is non-empty before submitting the form.","If calling the service directly, ensure request.SysAutoCodeCreate is fully populated instead of a zero value."],"exampleFix":"// before\n{ \"template\": \"package\" }\n// after\n{ \"template\": \"package\", \"packageName\": \"myapp\", \"description\": \"my business package\" }","handlingStrategy":"validation","validationCode":"const packageName = form.packageName?.trim()\nif (!packageName) {\n  throw new Error('PackageName不能为空!')\n}\nawait api.createPackage({ template: form.template, packageName })","typeGuard":null,"tryCatchPattern":"try {\n  await api.createPackage(payload)\n} catch (e) {\n  if (e?.msg === 'PackageName不能为空!') {\n    formRef.value.validateField('packageName')\n  } else { throw e }\n}","preventionTips":["Make packageName a required field in the form with non-empty rule.","Disable the submit button until packageName is filled.","When scripting API calls, build payloads from a schema checklist."],"tags":["validation","autocode","gin-vue-admin"],"backgroundTag":"missing-required-field","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}