flipped-aurora/gin-vue-admin · error
Package为空!
Error message
Package为空!
What it means
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.
Source
Thrown at server/model/system/request/sys_auto_code.go:200
if r.GvaModel {
r.PrimaryField = &AutoCodeField{
FieldName: "ID",
FieldType: "uint",
FieldDesc: "ID",
FieldJson: "ID",
DataTypeLong: "20",
Comment: "主键ID",
ColumnName: "id",
}
}
} // GvaModel
{
if r.IsAdd && r.PrimaryField == nil {
r.PrimaryField = new(AutoCodeField)
}
} // 新增字段模式下不关注主键
if r.Package == "" {
return errors.New("Package为空!")
} // 增加判断:Package不为空
packages := []rune(r.Package)
if len(packages) > 0 {
if packages[0] >= 97 && packages[0] <= 122 {
packages[0] = packages[0] - 32
}
r.PackageT = string(packages)
} // PackageT 是 Package 的首字母大写
return nil
}
func (r *AutoCode) History() SysAutoHistoryCreate {
bytes, _ := json.Marshal(r)
return SysAutoHistoryCreate{
Table: r.TableName,
Package: r.Package,
Request: string(bytes),
StructName: r.StructName,View on GitHub (pinned to 3136500ef3)
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
Example fix
// before
await createAutoCode({ tableName: 'users', fields })
// after
await createAutoCode({ tableName: 'users', package: 'example', fields }) Defensive patterns
Strategy: validation
Validate before calling
// client-side, before calling preview/create
if (!req.package || !String(req.package).trim()) {
throw new Error('package is required for code generation')
} Type guard
function hasPackage(r) {
return typeof r?.package === 'string' && r.package.trim().length > 0
} Try / catch
try {
await createAutoCode(req)
} catch (e) {
if (String(e.message).includes('Package为空')) {
formRef.value.validateField('package') // highlight the missing field
} else { throw e }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/e8f632efee3bfd51.
Report an issue: GitHub.