fix(backup): log restore errors via the central logger and harden cleanup

Replace raw console.error calls in the backup import/migrations routes with
createLogger + ErrorWithMetadata so restore failures flow through the standard
log transports (console + Redis). Wrap the temporary DB close in finally so a
close failure cannot 500 a successful restore, and log client-side restore and
analysis failures to the browser console.
This commit is contained in:
Thomas Camlong committed 2026-08-18 11:14:04 +02:00
1 parent 2a76bb185b
commit 6befc5ad41
4 files changed
+21 -6

No files matched your search

@@ -3,8 +3,13 @@ import path from "path";
import { NextResponse } from "next/server";
import { createLogger } from "@homarr/core/infrastructure/logs";
import { ErrorWithMetadata } from "@homarr/core/infrastructure/logs/error";
import { findMigrationsFolder } from "../shared";
const logger = createLogger({ module: "backupMigrationsRoute" });
interface JournalEntry {
idx: number;
version: string;
@@ -56,7 +61,7 @@ export async function GET() {
},
);
} catch (error) {
console.error("[backup/migrations] Failed to read migrations:", error);
logger.error(new ErrorWithMetadata("Failed to read migration files", {}, { cause: error }));
const message = error instanceof Error ? error.message : "Unknown error";
return NextResponse.json({ error: `Failed to read migrations: ${message}` }, { status: 500 });
}