| 1101 | } |
| 1102 | |
| 1103 | const encodeJsonError = ( |
| 1104 | input: Error, |
| 1105 | options: ErrorOptions | undefined, |
| 1106 | encodeDefect: (input: unknown) => Json |
| 1107 | ): JsonError => { |
| 1108 | const encoded: JsonError = { |
| 1109 | name: input.name, |
| 1110 | message: typeof input.message === "string" ? input.message : "" |
| 1111 | } |
| 1112 | if (options?.includeStack && typeof input.stack === "string") { |
| 1113 | encoded.stack = input.stack |
| 1114 | } |
| 1115 | if (!options?.excludeCause && input.cause !== undefined) { |
| 1116 | encoded.cause = encodeDefect(input.cause) |
| 1117 | } |
| 1118 | return encoded |
| 1119 | } |
| 1120 | |
| 1121 | const makeEncodeDefect = (options?: ErrorOptions): (input: unknown) => Json => { |
| 1122 | const seen = new WeakSet<object>() |