{"record":{"id":"2a118ea1f93e9257","repo":"Tencent/WeKnora","slug":"failed-to-list-faq-chunks-w","errorCode":null,"errorMessage":"failed to list FAQ chunks: %w","messagePattern":"failed to list FAQ chunks: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/knowledge_faq.go","lineNumber":1462,"sourceCode":"\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}\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}","sourceCodeStart":1444,"sourceCodeEnd":1480,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/knowledge_faq.go#L1444-L1480","documentation":"ExportFAQEntries lists all FAQ chunks for export via chunkRepo.ListAllFAQChunksForExport and wraps failures with this message. It means the underlying query over the FAQ knowledge's chunks failed (DB error), so the CSV export aborts and returns no data. Empty result sets are NOT an error — they export an empty CSV.","triggerScenarios":"Calling ExportFAQEntries(kbID) when ListAllFAQChunksForExport fails: DB connection error, query timeout scanning a very large FAQ knowledge, context cancellation, or a repository-level error (bad index, table lock).","commonSituations":"Exporting a huge FAQ knowledge base causing query timeouts; database maintenance/failover during export; context deadline from an HTTP gateway shorter than the export duration; missing DB indexes after schema changes.","solutions":["Inspect the wrapped DB error; fix connectivity or timeout issues and retry the export.","Increase the request/export timeout for large knowledge bases, or export via the JSON API in pages.","Verify DB indexes on (tenant_id, knowledge_id, chunk_type) supporting ListAllFAQChunksForExport.","Retry during a lower-traffic window if lock contention/timeouts are the cause."],"exampleFix":"// before: gateway timeout kills large exports\nclient := &http.Client{Timeout: 10 * time.Second}\n// after\nclient := &http.Client{Timeout: 5 * time.Minute} // allow full FAQ export scan","handlingStrategy":"retry","validationCode":"if err := db.PingContext(ctx); err != nil {\n\treturn fmt.Errorf(\"database unavailable; postpone FAQ export: %w\", err)\n}\nif deadline, ok := ctx.Deadline(); ok && time.Until(deadline) < 30*time.Second {\n\treturn errors.New(\"context deadline too short for FAQ export\")\n}","typeGuard":null,"tryCatchPattern":"data, err := svc.ExportFAQEntries(ctx, kbID, page, tagUUIDs, keyword, 0, \"\", \"\")\nif err != nil && strings.Contains(err.Error(), \"failed to list FAQ chunks\") {\n\tif errors.Is(err, context.DeadlineExceeded) {\n\t\t// large KB: retry with a longer deadline\n\t\tctx, cancel = context.WithTimeout(context.Background(), 5*time.Minute)\n\t\tdefer cancel()\n\t\tdata, err = svc.ExportFAQEntries(ctx, kbID, page, tagUUIDs, keyword, 0, \"\", \"\")\n\t}\n}","preventionTips":["Allocate generous timeouts for exports of large FAQ knowledge bases","Verify export-supporting indexes survive schema migrations","Avoid exports during DB maintenance/backup windows","Prefer paginated reads when a KB grows beyond thousands of entries"],"tags":["database","export","faq","query-timeout"],"backgroundTag":"faq-export-query-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}