vxcontrol/pentagi · error
knowledge: get document %s: %w
Error message
knowledge: get document %s: %w
What it means
GetDocument fetches a single knowledge document by UUID with no user scoping (admin path). It calls the SQLC query GetKnowledgeDocument; a not-found row, DB error, or canceled context is wrapped as 'knowledge: get document <id>'.
Source
Thrown at backend/pkg/database/knowledge/knowledge.go:314
} else {
rows, err := ks.db.ListUserKnowledgeDocuments(ctx, nsOf(userIDStr))
if err != nil {
return nil, fmt.Errorf("knowledge: list user docs: %w", err)
}
for _, r := range rows {
docs = append(docs, rowToModel(r.ID, r.Document, nullStr(r.Cmetadata), withContent))
}
}
return applyGoFilters(docs, filter), nil
}
// ---- GetDocument (admin) ----------------------------------------------------
func (ks *knowledgeStore) GetDocument(ctx context.Context, id string) (*model.KnowledgeDocument, error) {
row, err := ks.db.GetKnowledgeDocument(ctx, id)
if err != nil {
return nil, fmt.Errorf("knowledge: get document %s: %w", id, err)
}
return rowToModel(row.ID, row.Document, nullStr(row.Cmetadata), true), nil
}
// ---- GetUserDocument (user-scoped) ------------------------------------------
func (ks *knowledgeStore) GetUserDocument(ctx context.Context, userID int64, id string) (*model.KnowledgeDocument, error) {
row, err := ks.db.GetUserKnowledgeDocument(ctx, database.GetUserKnowledgeDocumentParams{
Uuid: id,
UserID: nsOf(strconv.FormatInt(userID, 10)),
})
if err != nil {
return nil, fmt.Errorf("knowledge: get user document %s: %w", id, err)
}
return rowToModel(row.ID, row.Document, nullStr(row.Cmetadata), true), nil
}
// ---- SearchDocuments (admin) ------------------------------------------------View on GitHub (pinned to ea665308ba)
Solutions
- Confirm the document UUID exists (query the embedding table or re-list documents).
- Handle sql.ErrNoRows specially to return a clean not-found to the caller instead of a raw DB error.
- Check DB connectivity if the wrapped error is connection-related.
- Re-run goose migrations if the embedding table is missing (fresh database).
Example fix
// before
row, err := ks.db.GetKnowledgeDocument(ctx, id)
if err != nil {
return nil, fmt.Errorf("knowledge: get document %s: %w", id, err)
}
// after
row, err := ks.db.GetKnowledgeDocument(ctx, id)
if errors.Is(err, sql.ErrNoRows) {
return nil, fmt.Errorf("knowledge: document %s not found", id)
}
if err != nil {
return nil, fmt.Errorf("knowledge: get document %s: %w", id, err)
} Defensive patterns
Strategy: type-guard
Validate before calling
if _, err := uuid.Parse(id); err != nil {
return nil, fmt.Errorf("invalid document id: %w", err)
} Type guard
func isNotFound(err error) bool {
return errors.Is(err, sql.ErrNoRows)
} Try / catch
doc, err := store.GetDocument(ctx, id)
if err != nil {
if isNotFound(err) {
return ErrDocumentNotFound // map to 404
}
return fmt.Errorf("fetch document: %w", err)
} Prevention
- Refresh stale document ids in the UI after any delete operation.
- Treat sql.ErrNoRows as a domain not-found error, not an internal error.
- Validate UUID format before issuing queries.
- Avoid long-lived caches of document ids.
When it happens
Trigger: Calling GetDocument (directly or via UpdateDocument/RenameDocument/DeleteDocument) with a UUID that does not exist in the embedding table, or when the database is unavailable.
Common situations: Admin UI holds a stale document id after the row was deleted by another session; id typos; sql.ErrNoRows on a document deleted concurrently between list and get.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- failed to get screenshot: %w
- failed to get search log: %w
- failed to get subtasks for task %d: %w
- failed to get tool call log: %w
- failed to get termlog: %w
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/cca4941f0d5b50c2.
Report an issue: GitHub.