Skip to content

fix: handle non-numeric input for multiple-choice parameters in set_new_value#1763

Open
prajakta128 wants to merge 3 commits into
ArduPilot:masterfrom
prajakta128:fix/set-new-value-multiple-choice-missing-try-except
Open

fix: handle non-numeric input for multiple-choice parameters in set_new_value#1763
prajakta128 wants to merge 3 commits into
ArduPilot:masterfrom
prajakta128:fix/set-new-value-multiple-choice-missing-try-except

Conversation

@prajakta128

Copy link
Copy Markdown
Contributor

The is_multiple_choice branch in set_new_value calls 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: 'Disabled'" is 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.

Checklist

  • Verified by a human programmer
  • Code follows our coding standards
  • No breaking changes or properly documented

Testing

  • Unit tests pass

Added two regression tests to tests/test_data_model_ardupilot_parameter.py:

  • test_set_new_value_multiple_choice_non_numeric_raises_friendly_error
  • test_set_new_value_multiple_choice_valid_numeric_string_succeeds

All 47 tests pass locally (Python 3.12.10, pytest-9.0.3).

…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.
@coveralls

coveralls commented Jun 23, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 28166442464

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Warning

No base build found for commit 4715196 on master.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 94.416%

Details

  • Patch coverage: No coverable lines changed in this PR.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 13377
Covered Lines: 12630
Line Coverage: 94.42%
Relevant Branches: 2069
Covered Branches: 1998
Branch Coverage: 96.57%
Branches in Coverage %: No
Coverage Strength: 2.82 hits per line

💛 - 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.
@prajakta128 prajakta128 force-pushed the fix/set-new-value-multiple-choice-missing-try-except branch from 366c56b to 5b1344f Compare June 25, 2026 11:20
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.

2 participants