Tencent/WeKnora · error · errWikiPageNotFoundInScope

%w: %s

Error message

%w: %s

What it means

When the slug was not found in any allowed scope, the resolver returns errWikiPageNotFoundInScope wrapped with the slug via %w: %s. Because it uses %w, callers can errors.Is(err, errWikiPageNotFoundInScope) to distinguish a clean miss from real failures (272/273). This is the resolver's canonical 'page does not exist in your allowed knowledge bases' outcome.

Source

Thrown at internal/agent/tools/wiki_route_resolver.go:159

				slug, scope.KnowledgeBaseID, err,
			)
		}
		if page == nil {
			continue
		}
		if page.KnowledgeBaseID != "" && page.KnowledgeBaseID != scope.KnowledgeBaseID {
			return nil, "", fmt.Errorf(
				"wiki page %s returned knowledge base %s while resolving allowed scope %s",
				slug, page.KnowledgeBaseID, scope.KnowledgeBaseID,
			)
		}
		kbID := scope.KnowledgeBaseID
		hits = append(hits, hit{page: page, kbID: kbID})
		routes.rememberPage(page, kbID)
	}
	switch len(hits) {
	case 0:
		return nil, "", fmt.Errorf("%w: %s", errWikiPageNotFoundInScope, slug)
	case 1:
		return hits[0].page, hits[0].kbID, nil
	default:
		owners := make([]string, 0, len(hits))
		for _, item := range hits {
			owners = append(owners, item.kbID)
		}
		return nil, "", fmt.Errorf("%w: slug %s belongs to %s", errWikiPageAmbiguous, slug, strings.Join(owners, ", "))
	}
}

// resolveWikiCreateKB selects a creation target only when server-side context
// is unambiguous: one cached provenance owner or one Wiki KB in scope.
func resolveWikiCreateKB(
	slug string,
	kbIDs []string,
	routes *WikiRouteResolver,
	serverHints ...string,

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Confirm the slug via page listing/search in the intended KB
  2. Check the page exists in a KB included in the allowed scopes; widen scopes if appropriate
  3. Handle it as a typed not-found in the tool layer and surface 'page not found' to the model/user
  4. If it was recently renamed, use the old-to-new slug mapping if one exists

Example fix

page, kbID, err := resolveUniqueWikiPage(ctx, slug, kbIDs, routes)
if err != nil && errors.Is(err, errWikiPageNotFoundInScope) {
    return &types.ToolResult{Success: false, Error: fmt.Sprintf("wiki page %q not found in accessible knowledge bases", slug)}, nil
}
Defensive patterns

Strategy: type-guard

Validate before calling

null

Type guard

func isWikiPageNotFoundInScope(err error) bool { return errors.Is(err, errWikiPageNotFoundInScope) }

Try / catch

page, kbID, err := resolveUniqueWikiPage(ctx, slug, kbIDs, routes)
if err != nil && errors.Is(err, errWikiPageNotFoundInScope) {
    return &types.ToolResult{Success: false, Error: fmt.Sprintf("page %q not found in allowed knowledge bases", slug)}, nil
}

Prevention

When it happens

Trigger: resolveUniqueWikiPage iterated every ordered scope, each GetPageBySlug returned ErrWikiPageNotFound (or nil page), yielding zero hits.

Common situations: Typo in the slug; page deleted or renamed; page exists only in a KB outside the caller's allowed scopes; wrong KB filter passed in kbIDs.

Related errors


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