{"record":{"id":"eed7dfc0b85a7e9a","repo":"Tencent/WeKnora","slug":"failed-to-get-faq-knowledge-w","errorCode":null,"errorMessage":"failed to get FAQ knowledge: %w","messagePattern":"failed to get FAQ knowledge: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/knowledge_faq_import.go","lineNumber":316,"sourceCode":"\n// csvEscape 转义 CSV 字段\nfunc csvEscape(s string) string {\n\tif strings.ContainsAny(s, \",\\\"\\n\\r\") {\n\t\t// 将内部引号替换为两个引号，并用引号包裹整个字段\n\t\treturn \"\\\"\" + strings.ReplaceAll(s, \"\\\"\", \"\\\"\\\"\") + \"\\\"\"\n\t}\n\treturn s\n}\n\n// saveFAQImportResultToDatabase 保存FAQ导入结果统计到数据库\nfunc (s *knowledgeService) saveFAQImportResultToDatabase(ctx context.Context,\n\tpayload *types.FAQImportPayload, progress *types.FAQImportProgress, originalTotalEntries int,\n) error {\n\t// 获取FAQ知识库实例\n\ttenantID := ctx.Value(types.TenantIDContextKey).(uint64)\n\tknowledge, err := s.repo.GetKnowledgeByID(ctx, tenantID, payload.KnowledgeID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get FAQ knowledge: %w\", err)\n\t}\n\n\t// 计算跳过的条目数（总数 - 完全成功 - 部分失败 - 完全失败）\n\tskippedCount := originalTotalEntries - progress.SuccessCount - progress.PartialFailedCount - progress.FailedCount\n\tif skippedCount < 0 {\n\t\tskippedCount = 0\n\t}\n\n\t// 创建导入结果统计\n\timportResult := &types.FAQImportResult{\n\t\tTotalEntries:       originalTotalEntries,\n\t\tSuccessCount:       progress.SuccessCount,\n\t\tFailedCount:        progress.FailedCount,\n\t\tPartialFailedCount: progress.PartialFailedCount,\n\t\tSkippedCount:       skippedCount,\n\t\tMergedCount:        progress.MergedCount,\n\t\tAddedCount:         progress.AddedCount,\n\t\tImportMode:         payload.Mode,","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/knowledge_faq_import.go#L298-L334","documentation":"Thrown by saveFAQImportResultToDatabase when repo.GetKnowledgeByID fails to load the FAQ knowledge record for the imported knowledge ID. A persistence-layer failure (or the knowledge was deleted mid-import), preventing result statistics from being written.","triggerScenarios":"Thrown at internal/application/service/knowledge_faq_import.go:316 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check database connectivity","Verify the knowledge record still exists and belongs to the tenant (not deleted during import)","Inspect the wrapped repository error for constraint/timeout details"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}