chatboxai/chatbox · error · Error
Knowledge base name cannot be empty
Error message
Knowledge base name cannot be empty
What it means
Thrown by afetch() (the unauthenticated fetch wrapper) when the response status is not in 2xx after all retries are exhausted within the loop, OR on the first non-ok response when retry=0. The message embeds `res.status` and a sanitised body (HTML error pages from nginx/cloudflare are replaced with the standard HTTP status text). Carries responseBody, statusCode, and requestId. Used by apiRequest for all non-authenticated provider calls.
Source
Thrown at src/main/knowledge-base/ipc-handlers.ts:170
) => {
try {
log.info(`ipcMain: kb:update, id=${id}, name=${name}, rerankModel=${rerankModel}, visionModel=${visionModel}`)
if (!id || id <= 0) {
throw new Error('Invalid knowledge base ID')
}
if (!name && rerankModel === undefined && visionModel === undefined) {
return 0
}
const db = getDatabase()
let sql = 'UPDATE knowledge_base SET '
const args: (string | number)[] = []
if (name !== undefined) {
if (!name.trim()) {
throw new Error('Knowledge base name cannot be empty')
}
sql += 'name = ?'
args.push(name.trim())
}
if (rerankModel !== undefined) {
if (args.length > 0) sql += ', '
sql += 'rerank_model = ?'
args.push(rerankModel ?? '')
}
if (visionModel !== undefined) {
if (args.length > 0) sql += ', '
sql += 'vision_model = ?'
args.push(visionModel ?? '')
}
sql += ' WHERE id = ?'
args.push(id)
const rs = await db.execute(sql, args)View on GitHub (pinned to 81571269ad)
Solutions
- Read `error.statusCode` first: 401/403 → fix key, 429 → slow down / upgrade plan, 5xx → transient, retry later, 404 → check apiHost/path.
- Inspect `error.responseBody` for the provider's structured error (HTML pages are already sanitised in the message but the raw body may still be present).
- For 5xx, retry with exponential backoff by passing a higher `retry` option to afetch; for 4xx (except 429) retrying will not help.
- For browser/renderer 5xx HTML responses, the message is already collapsed to the HTTP status text — confirm the provider endpoint and CORS config.
Example fix
// before
const res = await apiRequest({ url, method: 'POST', body })
// after
try {
const res = await apiRequest({ url, method: 'POST', body, retry: 2 })
} catch (e) {
if (e instanceof ApiError && e.statusCode === 429) await backoff()
if (e instanceof ApiError && e.statusCode && e.statusCode >= 500) retryLater()
throw e
} Defensive patterns
Strategy: retry
Validate before calling
function isRetryableStatus(status?: number): boolean {
return status === 429 || (typeof status === 'number' && status >= 500)
} Type guard
import { ApiError } from '../models/errors'
function isApiError(e: unknown): e is ApiError {
return e instanceof ApiError && typeof e.statusCode === 'number'
} Try / catch
try { return await afetch(url, init, { retry: 2 }) }
catch (e) {
if (e instanceof ApiError && isRetryableStatus(e.statusCode)) await backoff()
if (e instanceof ApiError && e.statusCode === 401) promptForApiKey()
throw e
} Prevention
- Pass a retry count for transient (5xx/429) endpoints; skip retries for 4xx (except 429).
- Read statusCode and responseBody before deciding to retry or surface to the user.
- Sanitize upstream HTML bodies yourself if you display the message (the lib already does this).
When it happens
Trigger: Provider returns 401/403 (bad/expired API key) with a JSON error body; 429 rate limit from the upstream; 5xx from the provider or an intermediate gateway (502/503/504 returning HTML); 404 because the apiHost + path is wrong; CORS preflight rejected in the browser renderer; network returns a captive-portal HTML page.
Common situations: Wrong API key → 401; usage spikes past provider rate limit → 429; provider outage → 503 HTML (sanitised to 'Service Unavailable'); misconfigured apiHost pointing to a path that 404s; browser build hitting a provider without CORS headers; self-hosted gateway returning nginx error pages.
Related errors
- Invalid pagination parameters
- ${response.status} ${response.statusText}: ${text}
- Failed to start preview server
- GitHub API error: ${response.status} ${response.statusText}
- Failed to fetch file: ${filePath}
AI-assisted analysis of chatboxai/chatbox@81571269ad (2026-08-12).
Data as JSON: /api/errors/731a6d702e418014.
Report an issue: GitHub.