{"record":{"id":"32d105e5ee752c55","repo":"Tencent/WeKnora","slug":"failed-to-build-tag-map-w","errorCode":null,"errorMessage":"failed to build tag map: %w","messagePattern":"failed to build tag map: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/knowledge_faq.go","lineNumber":1468,"sourceCode":"\tfaqKnowledge, err := s.findFAQKnowledge(ctx, tenantID, kb.ID)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif faqKnowledge == nil {\n\t\t// Return empty CSV with headers only\n\t\treturn s.buildFAQCSV(nil, nil), nil\n\t}\n\n\t// Get all FAQ chunks\n\tchunks, err := s.chunkRepo.ListAllFAQChunksForExport(ctx, tenantID, faqKnowledge.ID)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to list FAQ chunks: %w\", err)\n\t}\n\n\t// Build tag map for tag_id -> tag_name conversion\n\ttagMap, err := s.buildTagMap(ctx, tenantID, kbID)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to build tag map: %w\", err)\n\t}\n\n\treturn s.buildFAQCSV(chunks, tagMap), nil\n}\n\n// ExportFAQEntriesJSON 以 JSON 数组形式导出 FAQ 知识库下的全部条目，\n// 字段与 FAQEntryPayload 兼容，便于\"导出 → 编辑 → 重新 append 导入\"循环。\nfunc (s *knowledgeService) ExportFAQEntriesJSON(ctx context.Context, kbID string) ([]byte, error) {\n\tkb, err := s.validateFAQKnowledgeBase(ctx, kbID)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\ttenantID := ctx.Value(types.TenantIDContextKey).(uint64)\n\tfaqKnowledge, err := s.findFAQKnowledge(ctx, tenantID, kb.ID)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":1450,"sourceCodeEnd":1486,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/knowledge_faq.go#L1450-L1486","documentation":"ExportFAQEntries builds a tag_id -> tag_name map via buildTagMap so exported CSV rows carry readable tag names; failure is wrapped with this message. The chunks were listed successfully but tag lookup failed, so the export cannot render tag columns. Failures originate in the tag repository (DB query over the tenant's tags).","triggerScenarios":"Calling ExportFAQEntries when buildTagMap's tag repository query fails (DB error, timeout, context cancellation). This requires FAQ entries with TagIDs set; a KB with untagged entries and a tag-query failure can still hit it since buildTagMap runs unconditionally.","commonSituations":"Tag table corruption or missing rows; DB connectivity loss mid-export; very large tag tables making the map build slow enough to hit context deadlines; permission/tenant scoping errors in the tag repo.","solutions":["Check the wrapped tag-repo error and DB health; retry the export after connectivity is restored.","Verify the tag table and tenant-scoped indexes exist and are healthy.","As a workaround, export via JSON and map tag IDs to names client-side from the tag API.","Increase export timeouts if the tag table is large."],"exampleFix":"// resilient client-side fallback\ntagMap, err := svc.BuildTagMap(ctx, tenantID, kbID)\nif err != nil {\n\tlog.Warn(\"tag map unavailable, exporting with raw tag IDs\")\n\ttagMap = map[string]string{}\n}","handlingStrategy":"fallback","validationCode":"// confirm tags are queryable before export\nif _, err := tagRepo.GetByIDs(ctx, tenantID, []string{\"__probe__\"}); err != nil && !errors.Is(err, ErrNotFound) {\n\treturn fmt.Errorf(\"tag store unavailable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"data, err := svc.ExportFAQEntries(ctx, kbID, page, tagUUIDs, keyword, 0, \"\", \"\")\nif err != nil && strings.Contains(err.Error(), \"failed to build tag map\") {\n\t// fallback: export JSON and resolve tag names client-side\n\tjsonBytes, jErr := svc.ExportFAQEntriesJSON(ctx, kbID)\n\tif jErr == nil {\n\t\tdata = resolveTagsClientSide(jsonBytes)\n\t}\n}","preventionTips":["Keep the tag table and its tenant-scoped indexes healthy","Avoid running exports while bulk tag rename/delete jobs hold locks","Have a client-side tag-name resolution fallback for degraded modes","Raise export context timeouts on tenants with many tags"],"tags":["database","tags","export","faq"],"backgroundTag":"tag-lookup-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}