fix: ensure proper error message when backup operation is aborted
This commit is contained in:
parent
7879d88a54
commit
46c8139a23
3 changed files with 15 additions and 9 deletions
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue