Skip to content

Commit 631e924

Browse files
committed
Add try/catch w/ error message to plugin calls
1 parent c49c39a commit 631e924

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/core/init/lifecycle.js

+21-6
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,29 @@ export function Lifecycle(Base) {
3636
if (index >= queue.length) {
3737
next(data);
3838
} else if (typeof hookFn === 'function') {
39+
const errTitle = `Docsify plugin ${
40+
hookFn.name ? '"' + hookFn.name + '"' : ''
41+
} error (${hookName})`;
42+
3943
if (hookFn.length === 2) {
40-
hookFn(data, result => {
41-
data = result;
42-
step(index + 1);
43-
});
44+
try {
45+
hookFn(data, result => {
46+
data = result;
47+
});
48+
} catch (err) {
49+
console.error(errTitle, err);
50+
}
51+
step(index + 1);
4452
} else {
45-
const result = hookFn(data);
46-
data = result === undefined ? data : result;
53+
let result;
54+
55+
try {
56+
result = hookFn(data);
57+
} catch (err) {
58+
console.error(errTitle, err);
59+
}
60+
61+
data = result || data;
4762
step(index + 1);
4863
}
4964
} else {

0 commit comments

Comments
 (0)