decolua/9router · error · Error
Failed to import database
Error message
Failed to import database
What it means
ProfilePage's database import handler throws this when POST /api/settings/database (backup payload + password) responds non-2xx without a specific error field. The surrounding catch also surfaces 'Invalid backup file' for local parse failures, so this message specifically indicates the server rejected the import.
Source
Thrown at src/app/(dashboard)/dashboard/profile/page.js:715
};
const runImportDatabase = async (password) => {
const file = pendingImportRef.current;
if (!file) return;
setDbLoading(true);
try {
const raw = await file.text();
const payload = JSON.parse(raw);
const res = await fetch("/api/settings/database", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ ...payload, password }),
});
const data = await res.json().catch(() => ({}));
if (!res.ok) {
throw new Error(data.error || "Failed to import database");
}
await reloadSettings();
setDbStatus({ type: "success", message: "Database imported successfully" });
} catch (err) {
setDbStatus({ type: "error", message: err.message || "Invalid backup file" });
} finally {
pendingImportRef.current = null;
setDbLoading(false);
}
};
// Confirm password modal, then run export or import.
const handleDbAuthConfirm = async () => {
const { mode, password } = dbAuth;
setDbAuth({ open: false, mode: "", password: "" });
if (mode === "export") await handleExportDatabase(password);
else if (mode === "import") await runImportDatabase(password);View on GitHub (pinned to 90b52e06ff)
Solutions
- Check the network response status and body for the server's specific rejection reason
- Verify the admin password is correct
- Validate the backup JSON matches the expected export shape (keys the importer reads) before uploading
- Confirm the backup's schema version is compatible with the running server; regenerate the backup from the current version if possible
Example fix
// before
if (!res.ok) {
throw new Error(data.error || "Failed to import database");
}
// after
if (!res.ok) {
throw new Error(data.error || `Failed to import database (HTTP ${res.status})`);
} Defensive patterns
Strategy: validation
Validate before calling
// validate backup shape before upload
const payload = JSON.parse(fileText);
if (!payload || typeof payload !== "object") throw new Error("Invalid backup file");
if (!password) throw new Error("Admin password required to import"); Type guard
function isValidBackup(v) {
return v !== null && typeof v === "object" && !Array.isArray(v);
} Try / catch
try {
const res = await fetch("/api/settings/database", { method: "POST", body: JSON.stringify({ ...payload, password }) });
const data = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(data.error || `Failed to import database (HTTP ${res.status})`);
} catch (err) {
setDbStatus({ type: "error", message: err.message || "Invalid backup file" });
} Prevention
- Only import backups produced by the same (or compatible) server version
- Validate the backup JSON structure client-side before POSTing
- Confirm the admin password before starting the import
- Keep a copy of the pre-import DB so a failed restore is recoverable
When it happens
Trigger: POST /api/settings/database with {…payload, password} returns non-2xx: wrong admin password (401), backup JSON structurally invalid for the server's importer (400), or a DB write/restore error (500); also thrown when the response body lacks data.error.
Common situations: Importing a backup from a newer/older schema version the current server can't restore; wrong admin password in the import dialog; backup file edited or truncated before upload.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- Invalid database payload
- Failed to export database
- Access token is required
- Machine ID is required
- Invalid token format. Token appears too short.
AI-assisted analysis of decolua/9router@90b52e06ff (2026-08-30).
Data as JSON: /api/errors/7bd217cbb2243cef.
Report an issue: GitHub.