Skip to content

Commit

Permalink
Add try/catch w/ error message to plugin calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jhildenbiddle committed Feb 1, 2022
1 parent c49c39a commit 631e924
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/core/init/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 631e924

Please sign in to comment.