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

Throw error or warning if path do not match any file. #30

Open
Glazomer opened this issue Nov 29, 2020 · 0 comments
Open

Throw error or warning if path do not match any file. #30

Glazomer opened this issue Nov 29, 2020 · 0 comments

Comments

@Glazomer
Copy link

Problem:

If we pass array with one or more invalid path they just just skipped. It may be an issue because after calling require('glob-extra').expandPaths we don't know how many paths are not valid or is there any?

Example:

const paths = getArrayFromUserInput(); // ['./right/path/but/with/typoo/5.js', './path/that/do/not/exist/1.js', './path/to/two/or/three/files/*'];
const resolved = require('glob-extra').expandPaths()paths;
functionThatUserExpectsWorkOnFiveLinksButWorksOnFour(paths);

Solution:

Make new option options.errorOnNoMatch that will throw error it any of array's path do not match file.

// glob-extra/lib/index.js:11
const getFilesByMask = (pattern, options) => {
  const files = fg.sync(pattern, options);
  if (options.errorOnNoMatch && files.length == 0) {
    throw new Error('Could not match any files with given patten: ' + pattern);
  }
  return Promise.resolve(files);
};
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

No branches or pull requests

1 participant