File size: 923 Bytes
5cb63c1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import { restoreCronLoadError, serializeCronLoadError } from "./load-error.js";
export class CronJobsStoreChangedError extends Error {
constructor(storePath: string) {
super(`Cron store at ${storePath} changed after it was read; reload it before writing`);
this.name = "CronJobsStoreChangedError";
}
}
export type CronSaveError =
| { kind: "store-changed"; storePath: string }
| { kind: "other"; error: ReturnType<typeof serializeCronLoadError> };
export function serializeCronSaveError(error: unknown, storePath: string): CronSaveError {
return error instanceof CronJobsStoreChangedError
? { kind: "store-changed", storePath }
: { kind: "other", error: serializeCronLoadError(error) };
}
export function restoreCronSaveError(error: CronSaveError): Error {
return error.kind === "store-changed"
? new CronJobsStoreChangedError(error.storePath)
: restoreCronLoadError(error.error);
}
|