also looking at this
test: exercise full host filesystem recovery
#58
13 files
+644
-5
| @@ -0,0 +1,16 @@ | ||
| 1 | /** Bounded own error descriptors only, including actual SQLite/OS aggregate causes. */ | |
| 2 | export function storageErrorCodes(error: unknown) { | |
| 3 | const pending = [error], seen = new Set<unknown>(), codes: string[] = [] | |
| 4 | while (pending.length && seen.size < 32) { | |
| 5 | const item = pending.shift() | |
| 6 | if (!item || typeof item !== 'object' || seen.has(item)) continue | |
| 7 | seen.add(item) | |
| 8 | const code = Object.getOwnPropertyDescriptor(item, 'code')?.value | |
| 9 | if ((typeof code === 'string' || typeof code === 'number') && String(code).length <= 64) codes.push(String(code)) | |
| 10 | const cause = Object.getOwnPropertyDescriptor(item, 'cause')?.value | |
| 11 | if (cause !== undefined) pending.push(cause) | |
| 12 | const errors = Object.getOwnPropertyDescriptor(item, 'errors')?.value | |
| 13 | if (Array.isArray(errors)) pending.push(...errors.slice(0, 32)) | |
| 14 | } | |
| 15 | return codes | |
| 16 | } | |