mirror of
https://github.com/docsifyjs/docsify.git
synced 2026-10-17 04:31:18 +08:00
Add try/catch w/ error message to plugin calls
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user