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

Load exceptions in user resolvers are not reported #1023

Closed
patrick-steele-idem opened this issue Feb 14, 2018 · 1 comment · Fixed by #1024 or Urigo/tortilla#68
Closed

Load exceptions in user resolvers are not reported #1023

patrick-steele-idem opened this issue Feb 14, 2018 · 1 comment · Fixed by #1024 or Urigo/tortilla#68

Comments

@patrick-steele-idem
Copy link
Contributor

If there is an exception when loading a user resolver then the exception is not reported. For example, if there is a syntax error in a user resolver or if the user has a bad import then the exception is swallowed.

This problem is because of the try...catch around the require() calls: https://github.com/benmosher/eslint-plugin-import/blob/master/utils/resolve.js#L140-L155

It is much safer to use code that checks for the existence of a module using require.resolve():

function tryRequire(target) {
  let resolved;
  try {
    // Check if the target exists
    resolved = require.resolve(target);
  } catch(e) {
    // If the target does not exist then just return undefined
    return undefined;
  }

  // If the target exists then return the loaded module
  return require(resolved);
}

I will be submitting a PR.

@ljharb ljharb closed this as completed in 8778d7c Feb 18, 2018
ljharb added a commit that referenced this issue Feb 18, 2018
Fixes #1023 - Load exceptions in user resolvers are not reported
@ljharb
Copy link
Member

ljharb commented Feb 18, 2018

Fixed in #1024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment