File size: 1,207 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
26
27
28
29
30
31
32
import type { SqliteWorkerReply } from "../../infra/sqlite-worker-contract.js";
import {
  encodeOpenClawStateWorkerError,
  hydrateOpenClawStateWorkerError,
  retainOpenClawStateWorkerErrorPayload,
} from "../../state/openclaw-state-worker-error.js";

type CronLoadError = Extract<SqliteWorkerReply, { ok: false }>["error"];

export function serializeCronLoadError(value: unknown): CronLoadError {
  const error = value instanceof Error ? value : new Error(String(value));
  const code = "code" in error ? error.code : undefined;
  const sharedState = encodeOpenClawStateWorkerError(error, { includeOrdinary: true });
  return {
    name: error.name,
    message: error.message,
    ...(typeof code === "string" || typeof code === "number" ? { code } : {}),
    ...(sharedState ? { sharedState } : {}),
  };
}

export function restoreCronLoadError(value: CronLoadError): Error {
  const error = Object.assign(new Error(value.message), {
    name: value.name,
    ...(value.code === undefined ? {} : { code: value.code }),
  });
  if (value.sharedState) {
    retainOpenClawStateWorkerErrorPayload(error, value.sharedState);
  }
  return hydrateOpenClawStateWorkerError(error, { includeOrdinary: true });
}