(value, options = {})
| 181 | }; |
| 182 | |
| 183 | export function serializeError(value, options = {}) { |
| 184 | const { maxDepth = Number.POSITIVE_INFINITY, useToJSON = true } = options; |
| 185 | |
| 186 | if (typeof value === "object" && value !== null) { |
| 187 | return destroyCircular({ |
| 188 | from: value, |
| 189 | seen: [], |
| 190 | forceEnumerable: true, |
| 191 | maxDepth, |
| 192 | depth: 0, |
| 193 | useToJSON, |
| 194 | serialize: true, |
| 195 | }); |
| 196 | } |
| 197 | |
| 198 | // People sometimes throw things besides Error objects… |
| 199 | if (typeof value === "function") { |
| 200 | // `JSON.stringify()` discards functions. We do too, unless a function is thrown directly. |
| 201 | return `[Function: ${value.name ?? "anonymous"}]`; |
| 202 | } |
| 203 | |
| 204 | return value; |
| 205 | } |
| 206 | |
| 207 | export function isErrorLike(value) { |
| 208 | return ( |
no test coverage detected