{"record":{"id":"4a75c79261fbed75","repo":"Tencent/WeKnora","slug":"get-knowledge-base-w","errorCode":null,"errorMessage":"get knowledge base: %w","messagePattern":"get knowledge base: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/wiki_page.go","lineNumber":1255,"sourceCode":"// deleteChunkForPage removes the synced chunk for a wiki page. Chunk sync is\n// optional wiring, so a service built without a chunk repository just skips\n// it rather than taking the delete down with it.\nfunc (s *wikiPageService) deleteChunkForPage(ctx context.Context, page *types.WikiPage) {\n\tif s.chunkRepo == nil {\n\t\treturn\n\t}\n\tchunkID := \"wp-\" + page.ID\n\tif err := s.chunkRepo.DeleteChunk(ctx, page.TenantID, chunkID); err != nil {\n\t\tlogger.Warnf(ctx, \"wiki: failed to delete chunk for page %s: %v\", page.Slug, err)\n\t}\n}\n\n// createDefaultPage creates the default index page.\nfunc (s *wikiPageService) createDefaultPage(ctx context.Context, kbID string, slug string, title string, pageType string, content string) (*types.WikiPage, error) {\n\t// Get KB to get tenant ID\n\tkb, err := s.kbService.GetKnowledgeBaseByIDOnly(ctx, kbID)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"get knowledge base: %w\", err)\n\t}\n\n\tpage := &types.WikiPage{\n\t\tID:              uuid.New().String(),\n\t\tTenantID:        kb.TenantID,\n\t\tKnowledgeBaseID: kbID,\n\t\tSlug:            slug,\n\t\tTitle:           title,\n\t\tPageType:        pageType,\n\t\tStatus:          types.WikiPageStatusPublished,\n\t\tContent:         content,\n\t\tSummary:         title,\n\t\tVersion:         1,\n\t}\n\tnormalizeWikiHierarchy(page)\n\n\tif err := s.repo.Create(ctx, page); err != nil {\n\t\treturn nil, fmt.Errorf(\"create default %s page: %w\", slug, err)","sourceCodeStart":1237,"sourceCodeEnd":1273,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/wiki_page.go#L1237-L1273","documentation":"createDefaultPage seeds a default index page and first needs the knowledge base to obtain its tenant ID. If kbService.GetKnowledgeBaseByIDOnly fails, the error is wrapped as 'get knowledge base: %w'. It indicates the KB lookup itself failed (not-found or storage error) while auto-creating a default page.","triggerScenarios":"GetIndex on a KB whose default index page doesn't exist yet, where the KB lookup by ID fails — KB ID is wrong/deleted, DB error, or context cancellation.","commonSituations":"Requesting a wiki index for a knowledge base ID that was deleted or belongs to another tenant; stale IDs cached in clients after KB deletion; DB outage during first index access.","solutions":["Verify the kbID exists (call the KB get endpoint) before accessing the wiki index.","Check whether the knowledge base was deleted or moved to another tenant.","Inspect the wrapped error in logs to distinguish not-found from storage failures.","If the KB was legitimately removed, clean up clients/schedulers still referencing the old ID."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"kb, err := kbSvc.GetKnowledgeBaseByIDOnly(ctx, kbID)\nif err != nil || kb == nil {\n    return fmt.Errorf(\"KB %s does not exist; skip wiki index access\", kbID)\n}","typeGuard":null,"tryCatchPattern":"pages, err := svc.GetIndex(ctx, kbID)\nif err != nil && strings.Contains(err.Error(), \"get knowledge base:\") {\n    if errors.Is(err, repository.ErrNotFound) {\n        return ErrUnknownKnowledgeBase // surface as 404 to caller\n    }\n    return err // storage failure: retry or alert\n}","preventionTips":["Validate KB IDs exist before any wiki operations","Clean up references when knowledge bases are deleted","Confirm tenant scoping so cross-tenant IDs are rejected early","Distinguish not-found from storage errors via errors.Is on the wrapped cause"],"tags":["knowledge-base","not-found","wrapped-error"],"backgroundTag":"parent-resource-not-found","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}