Budibase/budibase · error · HTTPError
Knowledge base file not found
Error message
Knowledge base file not found
What it means
getKnowledgeBaseFileOrThrow fetches a KnowledgeBaseFile doc by ID from the workspace DB via db.tryGet. If no document exists with that ID, or it is flagged _deleted, an HTTPError 404 is thrown. removeKnowledgeBaseFile relies on it to load the file before deletion.
Source
Thrown at packages/server/src/sdk/workspace/ai/knowledgeBase/files.ts:90
_rev: rev,
}
}
export const updateKnowledgeBaseFile = async (
file: KnowledgeBaseFile
): Promise<KnowledgeBaseFile> => {
const db = context.getWorkspaceDB()
const updated = { ...file }
const { rev } = await db.put(file)
updated._rev = rev
return updated
}
export const getKnowledgeBaseFileOrThrow = async (fileId: string) => {
const db = context.getWorkspaceDB()
const file = await db.tryGet<KnowledgeBaseFile>(fileId)
if (!file || file._deleted) {
throw new HTTPError("Knowledge base file not found", 404)
}
return file
}
export const listKnowledgeBaseFiles = async (
knowledgeBaseId: string
): Promise<KnowledgeBaseFile[]> => {
const db = context.getWorkspaceDB()
const response = await db.allDocs<KnowledgeBaseFile>(
docIds.getDocParams(DocumentType.KNOWLEDGE_BASE_FILE, knowledgeBaseId, {
include_docs: true,
})
)
return response.rows
.map(row => row.doc)
.filter(file => !!file)
.filter(file => !file._deleted)
.sort((a, b) => {View on GitHub (pinned to a81a902e9a)
Solutions
- Check the file exists first with listKnowledgeBaseFiles or db.tryGet before deleting/fetching
- Treat the 404 as success if the goal is removal (idempotent delete)
- Verify the correct workspace DB is in context (context.getWorkspaceDB) for the app that owns the file
Example fix
// before
await sdk.ai.knowledgeBase.files.removeKnowledgeBaseFile(kb, file) // 404 if already gone
// after
try {
const file = await getKnowledgeBaseFileOrThrow(fileId)
await removeKnowledgeBaseFile(kb, file)
} catch (e) {
if (!(e instanceof HTTPError && e.status === 404)) throw e
} Defensive patterns
Strategy: try-catch
Validate before calling
const existing = await db.tryGet<KnowledgeBaseFile>(fileId)
if (!existing || existing._deleted) { /* skip or inform user */ } Try / catch
try {
const file = await getKnowledgeBaseFileOrThrow(fileId)
await removeKnowledgeBaseFile(kb, file)
} catch (e) {
if (e instanceof HTTPError && e.status === 404) return // already gone
throw e
} Prevention
- Make deletes idempotent by swallowing 404
- Refresh file lists in the UI before acting on a stored fileId
- Confirm the request runs in the workspace that owns the file
When it happens
Trigger: Calling getKnowledgeBaseFileOrThrow (directly or via removeKnowledgeBaseFile) with a fileId that does not exist in the workspace DB, or one that was already deleted (including race: deleted by another request just before).
Common situations: Client retries a delete of an already-deleted file; stale UI holding an old file ID after the KB was reset; wrong workspace context (file exists in another workspace/app DB); querying the wrong CouchDB.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Operation not found for this agent
- Custom REST template not found
- Automation not found
- Webhook not found
- Resource not found: ${body.resourceId}
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/445d8375d585ebfe.
Report an issue: GitHub.