panic fix: no version histories is mutable state #1
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.
What changed?
Handle error if version histories is nil instead of calling a method (
GetCurrentVersionHistory
) on a nil pointer.While returning an empty version histories might look like a good alternative, is not since everywhere in code we expect versions to be not empty. In addition, version histories also has index and it should always be valid (
0
refers tohistories[0]
).Why?
Because of panics in Uber production.
Having no version histories is considered OK by
getMutableState
which has:Which means, PollMutableState/GetMutableState should not panic on this. It is now returning error.
Could make it even better and handle case when initially there were no versions history, and then appeared, but:
a) an error instead of panic-ing is already better b) this will complicate tests
c) still not sure how valid this case is (isn't that a corrupted execution?)
How did you test it?
Added a new unit-test
Potential risks
Release notes
Documentation Changes