finally a correct way to throw errors
This commit is contained in:
+8
-1
@@ -56,6 +56,7 @@ import { SyncAlgoV2Modal } from "./syncAlgoV2Notice";
|
||||
import { applyPresetRulesInplace } from "./presetRules";
|
||||
|
||||
import { applyLogWriterInplace, log } from "./moreOnLog";
|
||||
import AggregateError from "aggregate-error";
|
||||
|
||||
const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
|
||||
s3: DEFAULT_S3_CONFIG,
|
||||
@@ -350,7 +351,13 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
log.error(msg);
|
||||
log.error(error);
|
||||
getNotice(msg, 10 * 1000);
|
||||
getNotice(error.message, 10 * 1000);
|
||||
if (error instanceof AggregateError) {
|
||||
for (const e of error.errors) {
|
||||
getNotice(e.message, 10 * 1000);
|
||||
}
|
||||
} else {
|
||||
getNotice(error.message, 10 * 1000);
|
||||
}
|
||||
this.syncStatus = "idle";
|
||||
if (this.syncRibbon !== undefined) {
|
||||
setIcon(this.syncRibbon, iconNameSyncWait);
|
||||
|
||||
+11
-1
@@ -5,6 +5,7 @@ import {
|
||||
Vault,
|
||||
requireApiVersion,
|
||||
} from "obsidian";
|
||||
import AggregateError from "aggregate-error";
|
||||
import PQueue from "p-queue";
|
||||
import {
|
||||
RemoteItem,
|
||||
@@ -1156,6 +1157,7 @@ export const doActualSync = async (
|
||||
}
|
||||
|
||||
const queue = new PQueue({ concurrency: concurrency, autoStart: true });
|
||||
const potentialErrors: Error[] = [];
|
||||
|
||||
for (let k = 0; k < singleLevelOps.length; ++k) {
|
||||
const val: FileOrFolderMixedState = singleLevelOps[k];
|
||||
@@ -1188,10 +1190,18 @@ export const doActualSync = async (
|
||||
|
||||
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();
|
||||
|
||||
if (potentialErrors.length > 0) {
|
||||
throw new AggregateError(potentialErrors);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user