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

set default execution period to avoid panic #51

Merged
merged 5 commits into from
Jul 1, 2021

Conversation

dmarkhas
Copy link
Collaborator

@dmarkhas dmarkhas commented Jun 7, 2021

If ExecutionPeriod option is unset on either the Health instance or the individual check, the code will panic when attempting to create a new ticker in scheduleCheck, since the execution period's default value is 0:

func NewTicker(d Duration) *Ticker {
	if d <= 0 {
		panic(errors.New("non-positive interval for NewTicker"))
	}
	....

@eranharel
Copy link
Contributor

please add a test that recreates the bug

@eranharel
Copy link
Contributor

I thought about this a little more, and I think that it would make more sense to return an error from Health.RegisterCheck() rather than surprise the user with a 1 min execution period.

@dmarkhas
Copy link
Collaborator Author

That would be a breaking change to the API (it will break at runtime, not at compile time) and I feel that it would make it confusing because it will start returning errors if an optional value is not provided, which kinda defeats the purpose of it being optional :-)

If a user registers a check without specifying an execution period, he probably "trusts" the library to have a safe default, and I think 1 minute accomplishes that goal.

@dmarkhas
Copy link
Collaborator Author

OTOH currently it will just panic in that condition...

Changed it to return an error + added tests

Copy link
Contributor

@eranharel eranharel left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Dan

@eranharel eranharel merged commit fb5b7bd into AppsFlyer:master Jul 1, 2021
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.

None yet

2 participants