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

fix: throw full error causing preprocessor to not load #5816

Merged
merged 2 commits into from
Nov 25, 2021

Conversation

Snugug
Copy link
Contributor

@Snugug Snugug commented Nov 23, 2021

Related to #5815, going through this function I found that the module was being resolved correctly but an error was being thrown during require, which the default error message swallowed. If I follow other uses of the debug helpers, this should throw the standard error unless the user's in debug mode, then it should debug the load error and throw the full stack trace.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

Related to vitejs#5815, going through this function I found that the module was being resolved correctly but an error was being thrown during `require`, which the default error message swallowed. If I follow other uses of the debug helpers, this should throw the standard error unless the user's in debug mode, then it should debug the load error and throw the full stack trace.
Comment on lines 1005 to 1012
if (isDebug) {
debug(`[load] Preprocessor dependency "${lang}" not found. Did you install it?`);
throw new Error(e.stack);
} else {
throw new Error(
`Preprocessor dependency "${lang}" not found. Did you install it?`
)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the error cause is useful even when you aren't debugging here. If there is a way to identify when the problem is that it wasn't installed, issue this message (that is friendly for 99% of the cases) and if it is installed, showing something like Preprocessor dependency "{lang} failed to load. ${e.message}
But we can leave it for a future PR, this is already an improvement. If the above isn't easy to implement, maybe we should move to a variable the repeated text before merging

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should do it

@Snugug Snugug changed the title Throws full error causing preprocessor to not load feat: Throw full error causing preprocessor to not load Nov 24, 2021
This switches up how the full error gets handled by throwing the normal error if the module can't be find, and throwing the full error, with combined stack, if there's an error loading the module.
@patak-dev patak-dev changed the title feat: Throw full error causing preprocessor to not load fix: throw full error causing preprocessor to not load Nov 25, 2021
@patak-dev patak-dev merged commit f6fcd21 into vitejs:main Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants