Tencent/WeKnora · error

get knowledge base: %w

Error message

get knowledge base: %w

What it means

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.

Source

Thrown at internal/application/service/wiki_page.go:1255

// deleteChunkForPage removes the synced chunk for a wiki page. Chunk sync is
// optional wiring, so a service built without a chunk repository just skips
// it rather than taking the delete down with it.
func (s *wikiPageService) deleteChunkForPage(ctx context.Context, page *types.WikiPage) {
	if s.chunkRepo == nil {
		return
	}
	chunkID := "wp-" + page.ID
	if err := s.chunkRepo.DeleteChunk(ctx, page.TenantID, chunkID); err != nil {
		logger.Warnf(ctx, "wiki: failed to delete chunk for page %s: %v", page.Slug, err)
	}
}

// createDefaultPage creates the default index page.
func (s *wikiPageService) createDefaultPage(ctx context.Context, kbID string, slug string, title string, pageType string, content string) (*types.WikiPage, error) {
	// Get KB to get tenant ID
	kb, err := s.kbService.GetKnowledgeBaseByIDOnly(ctx, kbID)
	if err != nil {
		return nil, fmt.Errorf("get knowledge base: %w", err)
	}

	page := &types.WikiPage{
		ID:              uuid.New().String(),
		TenantID:        kb.TenantID,
		KnowledgeBaseID: kbID,
		Slug:            slug,
		Title:           title,
		PageType:        pageType,
		Status:          types.WikiPageStatusPublished,
		Content:         content,
		Summary:         title,
		Version:         1,
	}
	normalizeWikiHierarchy(page)

	if err := s.repo.Create(ctx, page); err != nil {
		return nil, fmt.Errorf("create default %s page: %w", slug, err)

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Verify the kbID exists (call the KB get endpoint) before accessing the wiki index.
  2. Check whether the knowledge base was deleted or moved to another tenant.
  3. Inspect the wrapped error in logs to distinguish not-found from storage failures.
  4. If the KB was legitimately removed, clean up clients/schedulers still referencing the old ID.
Defensive patterns

Strategy: try-catch

Validate before calling

kb, err := kbSvc.GetKnowledgeBaseByIDOnly(ctx, kbID)
if err != nil || kb == nil {
    return fmt.Errorf("KB %s does not exist; skip wiki index access", kbID)
}

Try / catch

pages, err := svc.GetIndex(ctx, kbID)
if err != nil && strings.Contains(err.Error(), "get knowledge base:") {
    if errors.Is(err, repository.ErrNotFound) {
        return ErrUnknownKnowledgeBase // surface as 404 to caller
    }
    return err // storage failure: retry or alert
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/4a75c79261fbed75. Report an issue: GitHub.