flipped-aurora/gin-vue-admin · error

查询包失败!

Error message

查询包失败!

What it means

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.

Source

Thrown at server/service/system/auto_code_template.go:73

		if err != nil {
			return fmt.Errorf("plugin结构异常,缺少plugin/%s/plugin.go", Pkg)
		}
	}
	return nil
}

// Create 创建生成自动化代码
func (s *autoCodeTemplate) Create(ctx context.Context, info request.AutoCode) error {
	autoCodeCreateMu.Lock()
	defer autoCodeCreateMu.Unlock()

	// Frontend files are published last, but their Vite refresh may still cancel
	// the HTTP request before the handler returns. The accepted create task must finish.
	createCtx := autoCodeCreateContext(ctx)
	var autoPkg model.SysAutoCodePackage
	err := global.GVA_DB.WithContext(createCtx).Where("package_name = ?", info.Package).First(&autoPkg).Error
	if err != nil {
		return errors.Wrap(err, "查询包失败!")
	}
	err = s.checkPackage(info.Package, autoPkg.Template)
	if err != nil {
		return err
	}
	exists, err := autoCodeIdentityExists(createCtx, global.GVA_DB, info)
	if err != nil {
		return err
	}
	if exists {
		return errors.New("已经创建过此数据结构,请勿重复创建!")
	}

	layout, err := newAutoCodeTaskLayout(
		global.GVA_CONFIG.AutoCode.Root,
		global.GVA_CONFIG.AutoCode.Server,
		global.GVA_CONFIG.AutoCode.WebRoot(),
	)

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Verify info.Package matches an existing package in 系统工具 → 包管理 (package management list)
  2. Re-create the missing package before generating code
  3. Check DB connectivity and that the auto-code package table exists (run migrations)
  4. Confirm the request payload's package field is not empty or typo'd
  5. Inspect the wrapped gorm error in logs to distinguish not-found vs connection error

Example fix

// before
{ "packageName": "adminV1" }  // package was deleted
// after
// create package 'adminV1' in package management, or use an existing package name in the payload
Defensive patterns

Strategy: validation

Validate before calling

// client-side: ensure the package exists before generating
var cnt int64
global.GVA_DB.Model(&model.SysAutoCodePackage{}).
    Where("package_name = ?", req.Package).Count(&cnt)
if cnt == 0 {
    return errors.New("package not found: " + req.Package)
}

Try / catch

err := autoCodeSvc.Create(ctx, info)
if err != nil && strings.Contains(err.Error(), "查询包失败") {
    if errors.Is(errors.Unwrap(err), gorm.ErrRecordNotFound) {
        // recreate the package or pick a valid one
    } else {
        // DB connectivity/migration issue
    }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/fe6ba3f8d82b1d19. Report an issue: GitHub.