fix: ensure proper error message when backup operation is aborted
This commit is contained in:
parent
0323ff0031
commit
09805ce5ba
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");
|
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);
|
const abortController = runningBackups.get(scheduleId);
|
||||||
if (!abortController) {
|
if (!abortController) {
|
||||||
throw new ConflictError("No backup is currently running for this schedule");
|
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}`);
|
logger.info(`Stopping backup for schedule ${scheduleId}`);
|
||||||
|
|
||||||
abortController.abort();
|
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) => {
|
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.",
|
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.",
|
12: "Wrong repository password: The provided password for the repository is incorrect.",
|
||||||
130: "Backup interrupted: The backup process was interrupted.",
|
130: "Backup interrupted: The backup process was interrupted.",
|
||||||
|
999: "The backup was stopped by the user.",
|
||||||
};
|
};
|
||||||
|
|
||||||
export class ResticError extends Error {
|
export class ResticError extends Error {
|
||||||
|
|
|
||||||
|
|
@ -345,6 +345,11 @@ const backup = async (
|
||||||
logger.error(`Restic backup failed: ${res.stderr.toString()}`);
|
logger.error(`Restic backup failed: ${res.stderr.toString()}`);
|
||||||
logger.error(`Command executed: restic ${args.join(" ")}`);
|
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());
|
throw new ResticError(res.exitCode, res.stderr.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue