{"record":{"id":"080b3e621ec45a22","repo":"flipped-aurora/gin-vue-admin","slug":"error-080b3e","errorCode":null,"errorMessage":"模板不能为空!","messagePattern":"模板不能为空!","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_package.go","lineNumber":33,"sourceCode":"\t\"github.com/flipped-aurora/gin-vue-admin/server/model/system/request\"\n\t\"github.com/flipped-aurora/gin-vue-admin/server/utils\"\n\t\"github.com/flipped-aurora/gin-vue-admin/server/utils/ast\"\n\t\"github.com/flipped-aurora/gin-vue-admin/server/utils/autocode\"\n\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 {","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_package.go#L15-L51","documentation":"autoCodePackage.Create() validates the incoming SysAutoCodePackageCreate in a switch. The first case returns '模板不能为空!' when info.Template is the empty string — a package must declare which code-generation template it uses.","triggerScenarios":"Calling the auto-code package create API with a body where the template field is empty: omitted in JSON, sent as \"\", or bound from a form that never set the template.","commonSituations":"Frontend save button enabled before the user picks a template; API consumers constructing the payload manually and skipping the field; older clients using a renamed field name so Template binds empty.","solutions":["Set the template field in the request body (e.g. \"package\" for a package template).","Add required-field validation in the frontend form before submitting.","Check the JSON field name matches the request struct's binding tag so Template actually deserializes.","Retry the create call once template is selected."],"exampleFix":"// before\nawait api.createPackage({ packageName: 'order' }) // template omitted\n// after\nawait api.createPackage({ template: 'package', packageName: 'order' })","handlingStrategy":"validation","validationCode":"// pre-submit validation on the client\nif (!form.template) {\n  ElMessage.warning('请选择模板')\n  return\n}\nawait api.createPackage(form)","typeGuard":null,"tryCatchPattern":"try {\n  await svc.Create(ctx, info)\n} catch (err) {\n  if (err.Error() == \"模板不能为空!\") {\n    // return 400 with guidance to pick a template\n  } else {\n    return err\n  }\n}","preventionTips":["Mark template as a required field in the create form","Block submit until a template is selected","Match the JSON key names to the request struct binding tags","Add API-level schema validation for required fields"],"tags":["autocode","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"}