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

handle error on loading module, fix #1296 #1322

Closed
wants to merge 3 commits into from

Conversation

shigma
Copy link
Collaborator

@shigma shigma commented Feb 20, 2019

Summary

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Other, please describe:

If changing the UI of default theme, please provide the before/after screenshot:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:


Old non-string request resolution

Try to resolve the request as absolute/relative/dependency path and import them in chain. Use the first result as the resolved module. If any error was encounted, respective resolution will be skipped.

What are the drawbacks?

  1. It's not consistent with the implementation of Node.js. Node.js will take the first existing file as the final entry no matter it has errors or not.
  2. Referenced in Error in local theme index.js should not be ignored and reported as "cannot resolve plugin ..." #1296. A plain error log cannot resolve plugin may mislead user with an indication that the theme or plugin is not found instead of wrong.
  3. Whether the error is in the theme or plugin, the same error with plugin is displayed.

This PR's implementation

Try to resolve the request as absolute/relative/dependency path in chain.

  • If an entry file was found, vuepress will some the try-chain and try to load the file.
    • If the entry file is successfully loaded, apply it as a plugin/theme.
    • If an error was encounted, vuepress will leave a error log en error was encounted in plugin "xxx".
  • If all possible files do not exist, vuepress will leave a error log cannot resolve plugin "xxx".
  • If similar problem was encounted in theme entry file resolution, the error log will replace plugin with theme.

Breaking change

The probability that a breaking change occurs is rather small. Supposing there are two "entry" files with the same name. One is in the relative path (call it foo1), the other is a dependency of the project (call it foo2). Supposing foo1 has an error in it, and foo2 is normal:

// foo.js (foo1)
throw new Error()
// foo.js (foo2)
module.exports = {
  name: 'foo'
}

foo2 will be loaded with previous methods, while no module will be loaded in this PR.


The PR fulfills these requirements:

  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)

You have tested in the following browsers: (Providing a detailed version will be better.)

N/A

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature
  • Related documents have been updated
  • Related tests have been updated

To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.

@shigma shigma requested a review from ulivz February 24, 2019 13:35
@shigma
Copy link
Collaborator Author

shigma commented Mar 7, 2019

Moved to #1413.

@shigma shigma closed this Mar 7, 2019
@shigma shigma deleted the resolve-plugin-error-log branch March 7, 2019 13:18
@shigma shigma restored the resolve-plugin-error-log branch March 9, 2019 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant