fix: gracefully handle page loading failures during search indexing#2675
fix: gracefully handle page loading failures during search indexing#2675kokovtsev wants to merge 1 commit intodocsifyjs:developfrom
Conversation
|
@kokovtsev is attempting to deploy a commit to the Docsify Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug in the search plugin where indexing fails completely if any page linked in the sidebar fails to load. The fix ensures that the search index is saved with successfully loaded pages even when some pages fail to load, allowing users to search through available content.
Changes:
- Added error handler to
Docsify.getpromise to increment the counter even when page loading fails - Extracted counter increment logic into a
saveIfCompletedhelper function that is called in both success and error paths - Added comprehensive e2e test to verify search works when some pages fail to load
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/plugins/search/search.js | Adds error handler for failed page loads and refactors counter logic to ensure saveData is called even when some pages fail |
| test/e2e/search.test.js | Adds test case that verifies search functionality works when a broken page link is present in the sidebar |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| vm.router, | ||
| config.depth, | ||
| indexKey, | ||
| ); |
There was a problem hiding this comment.
The try-finally block will not catch errors thrown by genIndex. If genIndex throws an error (e.g., if window.marked.lexer fails or other processing errors occur), the error will propagate as an unhandled promise rejection. This should be a try-catch-finally block instead, with the catch block logging the error similar to how fetch errors are handled in the rejection handler below (lines 351-359). The catch block should log a warning message like "Search plugin: failed to generate index for file" and then the finally block should call saveIfCompleted to ensure indexing completes for other pages.
| ); | |
| ); | |
| } catch (err) { | |
| // eslint-disable-next-line no-console | |
| console.warn( | |
| 'Search plugin: failed to generate index for file', | |
| path, | |
| err, | |
| ); |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Summary
Gracefully handle page loading failures during the search indexing processing.
Before this fix, the loaded page counter was incremented only in the successful branch of
Docsify.get, so if any request failed then the counter never reached the expected value andsaveDatawas never called.Related issue, if any:
Fixes #2674
What kind of change does this PR introduce?
For any code change,
Does this PR introduce a breaking change?
Tested in the following browsers: