finally a correct way to throw errors

This commit is contained in:
fyears 2022-04-07 23:59:50 +08:00
parent 4686d911f4
commit 8270a02246
3 changed files with 20 additions and 2 deletions

View File

@ -62,6 +62,7 @@
"@fyears/tsqueue": "^1.0.1", "@fyears/tsqueue": "^1.0.1",
"@microsoft/microsoft-graph-client": "^3.0.1", "@microsoft/microsoft-graph-client": "^3.0.1",
"acorn": "^8.5.0", "acorn": "^8.5.0",
"aggregate-error": "^4.0.0",
"assert": "^2.0.0", "assert": "^2.0.0",
"aws-crt": "^1.10.1", "aws-crt": "^1.10.1",
"buffer": "^6.0.3", "buffer": "^6.0.3",

View File

@ -56,6 +56,7 @@ import { SyncAlgoV2Modal } from "./syncAlgoV2Notice";
import { applyPresetRulesInplace } from "./presetRules"; import { applyPresetRulesInplace } from "./presetRules";
import { applyLogWriterInplace, log } from "./moreOnLog"; import { applyLogWriterInplace, log } from "./moreOnLog";
import AggregateError from "aggregate-error";
const DEFAULT_SETTINGS: RemotelySavePluginSettings = { const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
s3: DEFAULT_S3_CONFIG, s3: DEFAULT_S3_CONFIG,
@ -350,7 +351,13 @@ export default class RemotelySavePlugin extends Plugin {
log.error(msg); log.error(msg);
log.error(error); log.error(error);
getNotice(msg, 10 * 1000); getNotice(msg, 10 * 1000);
if (error instanceof AggregateError) {
for (const e of error.errors) {
getNotice(e.message, 10 * 1000);
}
} else {
getNotice(error.message, 10 * 1000); getNotice(error.message, 10 * 1000);
}
this.syncStatus = "idle"; this.syncStatus = "idle";
if (this.syncRibbon !== undefined) { if (this.syncRibbon !== undefined) {
setIcon(this.syncRibbon, iconNameSyncWait); setIcon(this.syncRibbon, iconNameSyncWait);

View File

@ -5,6 +5,7 @@ import {
Vault, Vault,
requireApiVersion, requireApiVersion,
} from "obsidian"; } from "obsidian";
import AggregateError from "aggregate-error";
import PQueue from "p-queue"; import PQueue from "p-queue";
import { import {
RemoteItem, RemoteItem,
@ -1156,6 +1157,7 @@ export const doActualSync = async (
} }
const queue = new PQueue({ concurrency: concurrency, autoStart: true }); const queue = new PQueue({ concurrency: concurrency, autoStart: true });
const potentialErrors: Error[] = [];
for (let k = 0; k < singleLevelOps.length; ++k) { for (let k = 0; k < singleLevelOps.length; ++k) {
const val: FileOrFolderMixedState = singleLevelOps[k]; const val: FileOrFolderMixedState = singleLevelOps[k];
@ -1188,10 +1190,18 @@ export const doActualSync = async (
log.debug(`finished ${key}`); log.debug(`finished ${key}`);
}; };
queue.add(fn);
queue.add(fn).catch((e) => {
const msg = `${key}: ${e.message}`;
potentialErrors.push(new Error(msg));
});
} }
await queue.onIdle(); await queue.onIdle();
if (potentialErrors.length > 0) {
throw new AggregateError(potentialErrors);
}
} }
} }
}; };