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(): Normalize options.maxSize and throw errors where appropriate #397

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

coreydaley
Copy link

@coreydaley coreydaley commented Oct 31, 2024

The documentation does not make it very clear the difference between passing an integer and a string for maxSize, there also seems to be quite a bit of confusion around whether or not to use k or kb but there is no reason that k, kb and kilobytes can't all be used interchangeably (as an example). It also fails silently by just passing null to the file-stream-rotator package instead of letting the user know that they did something wrong and their option won't be used.

It also removes the silent rounding of the maxSize option that was happening, not sure why it was doing that, if users pass in a specific number, there is probably a reason for it.

This pull request starts off by renaming the getMaxSize function to something more appropriate normalizeMaxSize, it also updates the size option that is provided to getStream to determine more quickly if maxSize is undefined, and if so go ahead and just send null.

Next it normalizes the maxSize option and determines if it can return more quickly based upon the type of the data that is provided. Such that if an integer is provided, do a small check and bit of math and return it, if a string is provided, check to see if it was sent in an already correctly formatted quantifier and return it, if a longer quantifier was used, go ahead and parse it and assign the correct quantifier for passing it to the file-stream-rotator package.

It also now throws errors in the appropriate places if the provided option can not be parsed instead of just silently passing null to the file-stream-rotator package and confusing users.

I have not made any changes to the tests and as far as I can tell this change is not breaking and should not affect anyone in a negative way (unless they were passing in a crazy maxSize that was being ignored anyways) and this should also prevent issues being opened like #387

The documentation does not make it very clear the difference between
passing an integer and a string for maxSize, there also seems to be
quite a bit of confusion around whether or not to use `k` or `kb`
but there is no reason that `k`, `kb` and `kilobytes` can't all be
used interchangeably (as an example).

This pull request starts off by renaming the `getMaxSize` function
to something more appropriate `normalizeMaxSize`, it also updates
the `size` option that is provided to `getStream` to determine more
quickly if `maxSize` is undefined, and if so go ahead and just send
`null`.

Next it normalizes the `maxSize` option and determines if it can
return more quickly based upon the type of the data that is provided.
Such that if an integer is provided, do a small check and bit of math
and return it, if a string is provided, check to see if it was sent
in an already correctly formatted quantifier and return it, if
a longer quantifier was used, go ahead and parse it and assign the
correct quantifier for passing it to the file-stream-rotator package.

It also now throws errors in the appropriate places if the provided
option can not be parsed instead of just silently passing null to
the file-stream-rotator package and confusing users.
@coreydaley
Copy link
Author

@mattberther @indexzero Would one of you mind taking a look at this?
Thanks!

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.

1 participant