fix: handle non-numeric input for multiple-choice parameters in set_new_value#1763
Open
prajakta128 wants to merge 3 commits into
Open
Conversation
…ew_value The is_multiple_choice branch in set_new_value called float(s) with no try/except block. Both the is_bitmask and numeric branches properly catch ValueError and raise user-friendly translated error messages. If a user types a non-numeric string for a multiple-choice parameter (e.g. the choice label 'Disabled' instead of its numeric key '0'), the raw Python error 'could not convert string to float' was raised instead of a friendly translated message. Fixed by wrapping float(s) in a try/except ValueError matching the pattern already used in the bitmask and numeric branches. Add two regression tests covering the non-numeric error case and the valid numeric input case.
Coverage Report for CI Build 28166442464Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Warning No base build found for commit Coverage: 94.416%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats💛 - Coveralls |
…ew_value The is_multiple_choice branch in set_new_value called float(s) with no try/except block. Both the is_bitmask and numeric branches properly catch ValueError and raise user-friendly translated error messages. If a user types a non-numeric string for a multiple-choice parameter (e.g. the choice label 'Disabled' instead of its numeric key '0'), the raw Python error 'could not convert string to float' was raised instead of a friendly translated message. Fixed by wrapping float(s) in a try/except ValueError matching the pattern already used in the bitmask and numeric branches. Add two regression tests covering the non-numeric error case and the valid numeric input case.
366c56b to
5b1344f
Compare
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.
The
is_multiple_choicebranch inset_new_valuecallsfloat(s)with notry/exceptblock. Both theis_bitmaskand numeric branches properly catchValueErrorand raise user-friendly translated error messages.If a user types a non-numeric string for a multiple-choice parameter (e.g. the choice label
"Disabled"instead of its numeric key"0"), the raw Python error"could not convert string to float: 'Disabled'"is raised instead of a friendly translated message.Fixed by wrapping
float(s)in atry/except ValueError, matching the pattern already used in the bitmask and numeric branches.Checklist
Testing
Added two regression tests to tests/test_data_model_ardupilot_parameter.py:
All 47 tests pass locally (Python 3.12.10, pytest-9.0.3).