flipped-aurora/gin-vue-admin · error

获取历史记录失败: %v

Error message

获取历史记录失败: %v

What it means

performAnalysis fails at server/mcp/gva_analyze.go:105 when fetchAutoCodeHistories cannot load the autocode generation history records. The analysis aborts and the error is wrapped as "分析失败: 获取历史记录失败: ...". Packages may already have been fetched at this point, but no snapshot is returned.

Source

Thrown at server/mcp/gva_analyze.go:105

		return nil, fmt.Errorf("分析失败: %v", err)
	}

	// 序列化响应
	return textResultWithJSON("", response)
}

// performAnalysis 执行分析逻辑
func (g *GVAAnalyzer) performAnalysis(ctx context.Context, req AnalyzeRequest) (*AnalyzeResponse, error) {
	_ = req

	packages, err := fetchAutoCodePackages(ctx)
	if err != nil {
		return nil, fmt.Errorf("获取包信息失败: %v", err)
	}

	histories, err := fetchAutoCodeHistories(ctx)
	if err != nil {
		return nil, fmt.Errorf("获取历史记录失败: %v", err)
	}

	cleanupInfo := &CleanupInfo{
		DeletedPackages: []string{},
		DeletedModules:  []string{},
	}

	validPackages := make([]PackageInfo, 0, len(packages))
	var emptyPackageHistoryIDs []uint

	for _, pkg := range packages {
		isEmpty, err := g.isPackageFolderEmpty(pkg.PackageName, pkg.Template)
		if err != nil {
			logger.WithCtx(ctx).Mod("mcp").Err(err).Warn(fmt.Sprintf("检查包 %s 是否为空时出错", pkg.PackageName))
			continue
		}

		if isEmpty {

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Read the wrapped root error after the prefix for the actual DB/service failure.
  2. Verify the autocode history table exists (run AutoMigrate/migrations).
  3. Re-authenticate so ctx carries a valid token.
  4. Check DB connectivity/stability; retry gva_analyze once healthy.

Example fix

// before: history table missing
// 分析失败: 获取历史记录失败: Error 1146: table 'gva.sys_auto_code_history' doesn't exist
// after: run migrations to create the history table, then retry gva_analyze
Defensive patterns

Strategy: retry

Validate before calling

// verify the history table exists before calling
const ok = await db.query("SELECT 1 FROM sys_auto_code_histories LIMIT 1").then(() => true).catch(() => false)
if (!ok) throw new Error('autocode history table missing; run migrations')

Try / catch

try {
  return await callTool('gva_analyze', {})
} catch (e) {
  if (String(e.message).includes('获取历史记录失败')) {
    // check wrapped cause: missing table vs connection vs auth
    throw new Error('history fetch failed: ' + e.message)
  }
  throw e
}

Prevention

When it happens

Trigger: Calling gva_analyze when the history query fails: history table missing/not migrated, DB connection dropped between the two queries, ctx auth invalid, or service-layer error in fetchAutoCodeHistories.

Common situations: Partial migrations (packages table exists, history table doesn't); transient DB disconnects mid-request; expired JWT in the request context.

Related errors


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