Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Plugin error handling #1742

Merged
merged 22 commits into from
Mar 15, 2022
Merged
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
631e924
Add try/catch w/ error message to plugin calls
jhildenbiddle Feb 1, 2022
cfbcd81
Merge branch 'develop' into plugin-error-handling
jhildenbiddle Feb 1, 2022
67c5410
Update lifecycle.js
jhildenbiddle Feb 3, 2022
6cb9a58
Merge branch 'develop' into plugin-error-handling
jhildenbiddle Feb 3, 2022
2a58be6
Update lifecycle.js
jhildenbiddle Feb 3, 2022
e276411
Merge branch 'develop' into plugin-error-handling
jhildenbiddle Feb 5, 2022
0a9670e
Merge branch 'develop' into plugin-error-handling
jhildenbiddle Mar 7, 2022
97b91fa
Add try/catch to plugin pre-hooks
jhildenbiddle Mar 8, 2022
b808363
Update error message
jhildenbiddle Mar 8, 2022
2a39cea
Merge branch 'develop' into plugin-error-handling
jhildenbiddle Mar 8, 2022
c2bf5b9
Add catchPluginErrors option
jhildenbiddle Mar 10, 2022
99c9929
Fix async beforeEach calls
jhildenbiddle Mar 10, 2022
01aaced
Update plugin dev documentation
jhildenbiddle Mar 11, 2022
17f0313
Added catchPluginErrors option
jhildenbiddle Mar 11, 2022
bf72293
Remove unnecesary code block
jhildenbiddle Mar 11, 2022
c3c534c
Fix handling of hook return value
jhildenbiddle Mar 11, 2022
7ae61ea
Update template to handle no config scenario
jhildenbiddle Mar 11, 2022
89451d7
Update async hook text and examples
jhildenbiddle Mar 11, 2022
dd40e80
Add tests for catchPluginErrors option
jhildenbiddle Mar 11, 2022
a031405
Add tests for plugin system
jhildenbiddle Mar 11, 2022
70011e2
Update code samples
jhildenbiddle Mar 13, 2022
650870c
Merge branch 'develop' into plugin-error-handling
sy-records Mar 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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