{"record":{"id":"25f41c9e4429144e","repo":"Tencent/WeKnora","slug":"failed-to-ensure-faq-knowledge-w-25f41c","errorCode":null,"errorMessage":"failed to ensure FAQ knowledge: %w","messagePattern":"failed to ensure FAQ knowledge: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/knowledge_faq_import.go","lineNumber":70,"sourceCode":"\t\ttaskID = secutils.GenerateTaskID(\"faq_import\", tenantID, kbID)\n\t}\n\n\tvar knowledgeID string\n\n\t// 检查是否有正在进行的导入任务（通过Redis）\n\trunningTaskID, err := s.getRunningFAQImportTaskID(ctx, kbID)\n\tif err != nil {\n\t\tlogger.Errorf(ctx, \"Failed to check running import task: %v\", err)\n\t\t// 检查失败不影响导入，继续执行\n\t} else if runningTaskID != \"\" {\n\t\tlogger.Warnf(ctx, \"Import task already running for KB %s: %s\", kbID, runningTaskID)\n\t\treturn \"\", werrors.NewBadRequestError(fmt.Sprintf(\"该知识库已有导入任务正在进行中（任务ID: %s），请等待完成后再试\", runningTaskID))\n\t}\n\n\t// 确保 FAQ knowledge 存在\n\tfaqKnowledge, err := s.ensureFAQKnowledge(ctx, tenantID, kb)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to ensure FAQ knowledge: %w\", err)\n\t}\n\tknowledgeID = faqKnowledge.ID\n\n\t// 记录任务入队时间\n\tenqueuedAt := time.Now().Unix()\n\tinstanceID := uuid.NewString()\n\trunningInfoSet := false\n\tenqueueSucceeded := false\n\n\t// 设置 KB 的运行中任务信息\n\tif err := s.setRunningFAQImportInfo(ctx, kbID, &runningFAQImportInfo{\n\t\tTaskID:     taskID,\n\t\tEnqueuedAt: enqueuedAt,\n\t\tInstanceID: instanceID,\n\t}); err != nil {\n\t\tlogger.Errorf(ctx, \"Failed to set running FAQ import task info: %v\", err)\n\t\t// 不影响任务执行，继续\n\t} else {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/knowledge_faq_import.go#L52-L88","documentation":"Thrown when ensureFAQKnowledge fails to find or create the FAQ-type knowledge record for the knowledge base before importing entries. Wraps the underlying repository/persistence error; fires when the FAQ knowledge row is missing and cannot be auto-created, or the database is unreachable.","triggerScenarios":"Thrown at internal/application/service/knowledge_faq_import.go:70 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check database connectivity and retry the import","Verify the knowledge base exists and the FAQ knowledge record can be created (tenant quota, permissions)","Inspect the wrapped error for the exact repository failure"],"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"}