fix: ensure proper error message when backup operation is aborted
Some checks failed
Release Workflow / determine-release-type (push) Has been cancelled
Release Workflow / build-images (push) Has been cancelled
Release Workflow / publish-release (push) Has been cancelled

This commit is contained in:
Nicolas Meienberger 2025-12-19 23:27:25 +01:00
parent 7879d88a54
commit 46c8139a23
3 changed files with 15 additions and 9 deletions

View file

@ -425,15 +425,6 @@ const stopBackup = async (scheduleId: number) => {
throw new NotFoundError("Backup schedule not found");
}
await db
.update(backupSchedulesTable)
.set({
lastBackupStatus: "error",
lastBackupError: "Backup was stopped by user",
updatedAt: Date.now(),
})
.where(eq(backupSchedulesTable.id, scheduleId));
const abortController = runningBackups.get(scheduleId);
if (!abortController) {
throw new ConflictError("No backup is currently running for this schedule");
@ -442,6 +433,15 @@ const stopBackup = async (scheduleId: number) => {
logger.info(`Stopping backup for schedule ${scheduleId}`);
abortController.abort();
await db
.update(backupSchedulesTable)
.set({
lastBackupStatus: "warning",
lastBackupError: "Backup was stopped by user",
updatedAt: Date.now(),
})
.where(eq(backupSchedulesTable.id, scheduleId));
};
const runForget = async (scheduleId: number, repositoryId?: string) => {

View file

@ -26,6 +26,7 @@ const resticErrorCodes: Record<number, string> = {
11: "Failed to lock repository: Unable to acquire a lock on the repository. Try to run doctor on the repository.",
12: "Wrong repository password: The provided password for the repository is incorrect.",
130: "Backup interrupted: The backup process was interrupted.",
999: "The backup was stopped by the user.",
};
export class ResticError extends Error {

View file

@ -345,6 +345,11 @@ const backup = async (
logger.error(`Restic backup failed: ${res.stderr.toString()}`);
logger.error(`Command executed: restic ${args.join(" ")}`);
if (options?.signal?.aborted) {
logger.error("Restic backup was aborted by signal.");
throw new ResticError(999, "Backup operation stopped by user.");
}
throw new ResticError(res.exitCode, res.stderr.toString());
}