Add try/catch w/ error message to plugin calls

This commit is contained in:
John Hildenbiddle
2022-02-01 08:32:07 -06:00
parent c49c39a4a2
commit 631e924878
+21 -6
View File
@@ -36,14 +36,29 @@ export function Lifecycle(Base) {
if (index >= queue.length) {
next(data);
} else if (typeof hookFn === 'function') {
const errTitle = `Docsify plugin ${
hookFn.name ? '"' + hookFn.name + '"' : ''
} error (${hookName})`;
if (hookFn.length === 2) {
hookFn(data, result => {
data = result;
step(index + 1);
});
try {
hookFn(data, result => {
data = result;
});
} catch (err) {
console.error(errTitle, err);
}
step(index + 1);
} else {
const result = hookFn(data);
data = result === undefined ? data : result;
let result;
try {
result = hookFn(data);
} catch (err) {
console.error(errTitle, err);
}
data = result || data;
step(index + 1);
}
} else {