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 error caused by the absence of files when starting gulp task #49

Conversation

KolinRobinson
Copy link
Contributor

If there are no files in the folder, then task
.pipe (size ({
'gzip': true,
'pretty': true,
'showFiles': true,
'showTotal': true
}))
gives an error message

TypeError: Expected a finite number, got undefined: undefined
at module.exports (W: \ Freelance \ Easy-webdev-startpack \ node_modules \ pretty-bytes \ index.js: 70: 9)
at Transform._flush (W: \ Freelance \ Easy-webdev-startpack \ node_modules \ gulp-size \ index.js: 115: 21).

This fix solves this error, allowing you not to write additional functionality (in the form of disabling tasks if the folder with files is empty).

Thanks for attention!

Link to the task on which the error is caused: budfy/Easy-webdev-startpack@50ad1fe#diff-6e5c91cb2762eb968b4beffd0b5f42b94a46c4b6b5400195cb64ed98787a09a2

@sindresorhus
Copy link
Owner

CI is failing. Always run npm test locally before pushing changes.

@sindresorhus
Copy link
Owner

The PR also need a proper descriptive title.

fixed testing errors
@KolinRobinson KolinRobinson changed the title minor fix Fix error caused by the absence of files when starting gulp task Jun 3, 2021
@KolinRobinson
Copy link
Contributor Author

Thanks for the comments. Corrected.

index.js Outdated
this.prettySize = prettyBytes(this.size);
if (this.size) {
this.prettySize = prettyBytes(this.size);
}
Copy link
Owner

@sindresorhus sindresorhus Jun 3, 2021

Choose a reason for hiding this comment

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

prettySize is documented to always exist, so it should fall back to 0 for this.size. Just do a ternary.

Added ternary operator, which in case of undefined will pass 0
@sindresorhus
Copy link
Owner

This is not what I asked. You need to add the fallback to this.size, as it's also expected to not be undefined.

@KolinRobinson
Copy link
Contributor Author

Sorry, this is my first PL.

If there are no files, this.size is undefined, which cannot be processed by the prettyBytes () method, which causes a gulp error. In this case, I see a solution either
this.size = totalSize.values ​​(). next (). value || 0;
or
this.prettySize = prettyBytes (this.size || 0);

@sindresorhus
Copy link
Owner

this.size = totalSize.values ​​(). next (). value || 0;

This is what I meant.

Add default value for size if totalSize undefined
@KolinRobinson
Copy link
Contributor Author

Okay. Thanks a lot!

@sindresorhus sindresorhus merged commit 3980cc9 into sindresorhus:main Jun 3, 2021
@KolinRobinson KolinRobinson deleted the fix-sizes-error-if-there-are-no-files branch June 3, 2021 20:12
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.

2 participants