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

Better error message if file is missing #221

Open
ivanhofer opened this issue Apr 23, 2021 · 6 comments
Open

Better error message if file is missing #221

ivanhofer opened this issue Apr 23, 2021 · 6 comments

Comments

@ivanhofer
Copy link

ivanhofer commented Apr 23, 2021

It took me a while to realize what was wrong: the file I tried to test was missing, because I forgot to build my library before I ran npm size-limit.

I got following error message:

✖ Adding to empty webpack project
 ERROR  WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.

It would be a nice UX improvements when the error could be catched and a "human-readable" error message would be displayed instead. Something like: "Could not test {{name}} because file '{{path}}' is missing"

used package-versions:

@size-limit/preset-app: ^4.10.2
@size-limit/webpack: 4.10.2
size-limit: 4.10.2
@ai
Copy link
Owner

ai commented Apr 23, 2021

Please send PR

@ivanhofer
Copy link
Author

Hi @ai,

i could not get the tests running on my machine for the current main branch, so I can't change and push anything.

My PR would look like:

file: packages/webpack/get-config.js

let writeFile = promisify(fs.writeFile)
+let readFile = promisify(fs.readFile)

const STATIC = /\.(eot|woff2?|ttf|otf|svg|png|jpe?g|gif|webp|mp4|mp3|ogg|pdf|html|ico|md)$/

+async function checkIfFilesExist(limitConfig, check) {
+  const filesToCheck = []
+  for (const file of check.files) {
+    filesToCheck.push(file)
+  }
+  if (check.path) {
+    filesToCheck.push(join(limitConfig.cwd, check.path))
+  }
+
+  for (const file of filesToCheck) {
+    await readFile(file)
+      .catch(() => { throw Error(`Could not test '${check.name}' because file '${file}' is missing`) })
+  }
+}
+
module.exports = async function getConfig(limitConfig, check, output) {
+  await checkIfFilesExist(limitConfig, check)
+
  if (check.import) {

@ai
Copy link
Owner

ai commented May 1, 2021

  1. You need to use fs.existsSync rather than readFile. existsSync is faster.
  2. Send PR and run tests on CI
  3. This simple fix does not cover all cases. It falls on webpack’s supports ignore test.

ivanhofer added a commit to ivanhofer/size-limit that referenced this issue May 4, 2021
fixe: Better error message if file is missing ai#221
@ivanhofer
Copy link
Author

I now have disabled all git-hooks locally to be able to push to this repository.
I will wait until the CI workflow is approved

@ai
Copy link
Owner

ai commented May 4, 2021

I now have disabled all git-hooks locally to be able to push to this repository.

What error did you have?

@ivanhofer
Copy link
Author

I get o lot of different errors:

Error: Failed to launch the browser process! /mnt/c/Users/privat/projects/size-limit/node_modules/estimo/temp/chrome/linux-706915/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory

Timeout - Async callback was not invoked within the 10000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 10000 ms timeout specified by jest.setTimeout.Error

" ERROR dual-publish error: ERROR Error: EACCES: permission denied, rename '/packages/size-limit/test/fixtures/integration-esm/tmpCZQGqE' -> '/packages/size-limit/test/fixtures/integration-esm/dual-publish-tmp'

ivanhofer added a commit to ivanhofer/size-limit that referenced this issue May 5, 2021
Better error message if file is missing ai#221
ivanhofer added a commit to ivanhofer/size-limit that referenced this issue May 6, 2021
Better error message if file is missing ai#221
ivanhofer added a commit to ivanhofer/size-limit that referenced this issue May 13, 2021
Better error message if file is missing ai#221
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

2 participants