-
-
Notifications
You must be signed in to change notification settings - Fork 734
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
chore: add new parsing function for env var numbers #7947
Closed
thomasheartman
wants to merge
3
commits into
main
from
chore/1-2724-double-check-that-env-variables-override-config
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually thinking of having another function, but having the min here might be ok. When I see options it looks like the function is doing too much.
Maybe instead of having:
you can do something like:
My idea was that this should fail if you provide the wrong value, leaning on fail fast rather than allowing you to have issues at runtime.
But if we just want to ignore the user input (in this case the negative value), I'd stick with your solution of using Math.max function from before.
I still think that in this case of a startup configuration parameter, it's best to fail fast than to assume the customer input is invalid and then add a minimum value of our own, because we might be doing something the customer does not expect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for clarity: are you talking about the whole options object, or the
optionsOverride
property?Yeah, and I still don't agree with this. I don't think we do this with any other values, right? Sure, if we can't connect to the database, we die, but not because we verify it.
Also, what would be the use case for setting negative numbers? Or in this case, 0 for strategies? Without strategies, Unleash doesn't work (or you know, flags don't do anything). (But then again, we all know users do the wildest things, so 💁🏼 )
Yeah, I don't mind that, to be honest. The one thing I do think that's nice here is the fact that it does the
??
for us and that it's tested. But it's pretty small, and not that important anyway 🤷🏼There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, we could also just define another function in the same file and use that when defining the values:
But it doesn't really address any of the other bits here and it'd be untested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About the whole options object that includes the optionsOverride. Usually, having an options parameter is a code-smell because means that the function is less composable and it fulfills more than one purpose (which can be modified or disabled by the use of different options).
Indeed, the whole point of failing is to tell them not to add a negative number. Probably their intention is different than just having the value 1 (otherwise they would just configure 1, right?). So, I rather tell them, "hey! this is invalid, you can't do this" instead of: "Yeah, I see you want to set a negative number, but I will assume you wanted to say 1 because I don't understand why you want to set this to negative" (now that I think about it, maybe they want infinite... and one would be way lower than infinite)