{"record":{"id":"fe6ba3f8d82b1d19","repo":"flipped-aurora/gin-vue-admin","slug":"error-fe6ba3","errorCode":null,"errorMessage":"查询包失败!","messagePattern":"查询包失败!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_template.go","lineNumber":73,"sourceCode":"\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"plugin结构异常,缺少plugin/%s/plugin.go\", Pkg)\n\t\t}\n\t}\n\treturn nil\n}\n\n// Create 创建生成自动化代码\nfunc (s *autoCodeTemplate) Create(ctx context.Context, info request.AutoCode) error {\n\tautoCodeCreateMu.Lock()\n\tdefer autoCodeCreateMu.Unlock()\n\n\t// Frontend files are published last, but their Vite refresh may still cancel\n\t// the HTTP request before the handler returns. The accepted create task must finish.\n\tcreateCtx := autoCodeCreateContext(ctx)\n\tvar autoPkg model.SysAutoCodePackage\n\terr := global.GVA_DB.WithContext(createCtx).Where(\"package_name = ?\", info.Package).First(&autoPkg).Error\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"查询包失败!\")\n\t}\n\terr = s.checkPackage(info.Package, autoPkg.Template)\n\tif err != nil {\n\t\treturn err\n\t}\n\texists, err := autoCodeIdentityExists(createCtx, global.GVA_DB, info)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif exists {\n\t\treturn errors.New(\"已经创建过此数据结构,请勿重复创建!\")\n\t}\n\n\tlayout, err := newAutoCodeTaskLayout(\n\t\tglobal.GVA_CONFIG.AutoCode.Root,\n\t\tglobal.GVA_CONFIG.AutoCode.Server,\n\t\tglobal.GVA_CONFIG.AutoCode.WebRoot(),\n\t)","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_template.go#L55-L91","documentation":"AutoCodeTemplateService.Create (the code generation entry) first looks up the target package row: SELECT from the package table WHERE package_name = ?. If GORM returns an error (including ErrRecordNotFound), it is wrapped as '查询包失败!'. Generation cannot proceed without a valid package/template binding.","triggerScenarios":"Calling the auto-code create API with info.Package that has no matching row in the package table, or the DB query itself errors (connection failure, table missing because migrations did not run).","commonSituations":"User deleted the package in package management but an old client keeps generating against it; package_name mismatch (typo or casing); fresh environment where AutoMigrate did not create the packages table; DB connectivity blips.","solutions":["Verify info.Package matches an existing package in 系统工具 → 包管理 (package management list)","Re-create the missing package before generating code","Check DB connectivity and that the auto-code package table exists (run migrations)","Confirm the request payload's package field is not empty or typo'd","Inspect the wrapped gorm error in logs to distinguish not-found vs connection error"],"exampleFix":"// before\n{ \"packageName\": \"adminV1\" }  // package was deleted\n// after\n// create package 'adminV1' in package management, or use an existing package name in the payload","handlingStrategy":"validation","validationCode":"// client-side: ensure the package exists before generating\nvar cnt int64\nglobal.GVA_DB.Model(&model.SysAutoCodePackage{}).\n    Where(\"package_name = ?\", req.Package).Count(&cnt)\nif cnt == 0 {\n    return errors.New(\"package not found: \" + req.Package)\n}","typeGuard":null,"tryCatchPattern":"err := autoCodeSvc.Create(ctx, info)\nif err != nil && strings.Contains(err.Error(), \"查询包失败\") {\n    if errors.Is(errors.Unwrap(err), gorm.ErrRecordNotFound) {\n        // recreate the package or pick a valid one\n    } else {\n        // DB connectivity/migration issue\n    }\n}","preventionTips":["Delete stale generated-code requests referencing removed packages","Verify package name casing against the package management list","Run migrations so the package table exists on fresh environments","Add DB health checks before bulk generation jobs"],"tags":["gorm","database","auto-code","record-not-found"],"backgroundTag":"record-not-found","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}