fix(vchordg): avoid panic when validating an empty alpha option#468
Open
ameyypawar wants to merge 1 commit into
Open
fix(vchordg): avoid panic when validating an empty alpha option#468ameyypawar wants to merge 1 commit into
ameyypawar wants to merge 1 commit into
Conversation
`validate_alpha` indexes `alpha[0]` after the sorted/range checks, both of which pass on an empty slice (`[].is_sorted()` and `[].iter().all(..)` are true). So an empty `alpha` (e.g. `WITH (options='[index] alpha = []')`) panics with an index-out-of-bounds instead of returning a ValidationError. Use `alpha.first()` so the empty case yields the existing "`alpha` should contain `1.0`" error. Behavior is unchanged for every non-empty input. Add unit tests covering the empty slice plus valid/invalid cases.
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
VchordgIndexOptions::validate_alphaindexesalpha[0]after theis_sorted()and range checks — both of which are vacuously true for an empty slice:So an empty
alphapanics (index out of bounds) instead of returning aValidationError. It's reachable from SQL viaWITH (options = '[index] alpha = []'), which surfaces a cryptic panic message rather than a clean validation error.Fix
Use
alpha.first()so the empty case yields the existing`alpha` should contain `1.0`error:For any non-empty input
alpha.first() == Some(&alpha[0]), so behavior is unchanged; only the empty slice goes from panic to a proper validation error.Tests
Adds unit tests for
validate_alphacovering the empty slice (regression) plus valid/invalid cases. These run under the existingcargo test --workspace --exclude vchordjob (vchordgis a pure-Rust crate).Happy to adjust the wording or drop the tests if you'd prefer a more minimal change.