(args, label, options = {})
| 284 | } |
| 285 | |
| 286 | async function retrySimdeckJson(args, label, options = {}) { |
| 287 | const attempts = options.attempts ?? 3; |
| 288 | const delayMs = options.delayMs ?? 2_000; |
| 289 | let lastError; |
| 290 | for (let attempt = 1; attempt <= attempts; attempt += 1) { |
| 291 | try { |
| 292 | return simdeckJson(args, options); |
| 293 | } catch (error) { |
| 294 | lastError = error; |
| 295 | if (attempt < attempts) { |
| 296 | console.warn( |
| 297 | `${label} attempt ${attempt}/${attempts} failed; retrying in ${delayMs}ms: ${error?.message ?? error}`, |
| 298 | ); |
| 299 | await sleep(delayMs); |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | throw new Error( |
| 304 | `${label} failed after ${attempts} attempts: ${lastError?.message ?? lastError}`, |
| 305 | ); |
| 306 | } |
| 307 | |
| 308 | function runJson(command, args, options = {}) { |
| 309 | return JSON.parse(runText(command, args, options)); |
no test coverage detected