From 303f47f7c1a0df87b065fcf050b13d7960a6489c Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Fri, 8 Apr 2022 09:32:36 +0800 Subject: [PATCH] add hints for too many errors --- src/sync.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/sync.ts b/src/sync.ts index 1a643b3..477b71c 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -1158,6 +1158,7 @@ export const doActualSync = async ( const queue = new PQueue({ concurrency: concurrency, autoStart: true }); const potentialErrors: Error[] = []; + let tooManyErrors = false; for (let k = 0; k < singleLevelOps.length; ++k) { const val: FileOrFolderMixedState = singleLevelOps[k]; @@ -1194,12 +1195,22 @@ export const doActualSync = async ( queue.add(fn).catch((e) => { const msg = `${key}: ${e.message}`; potentialErrors.push(new Error(msg)); + if (potentialErrors.length >= 3) { + tooManyErrors = true; + queue.pause(); + queue.clear(); + } }); } await queue.onIdle(); if (potentialErrors.length > 0) { + if (tooManyErrors) { + potentialErrors.push( + new Error("too many errors, stop the remaining tasks") + ); + } throw new AggregateError(potentialErrors); } }