fix: avoid panic when a parameter override is an empty YAML array#638
Open
Lots-ninety-nine wants to merge 1 commit into
Open
fix: avoid panic when a parameter override is an empty YAML array#638Lots-ninety-nine wants to merge 1 commit into
Lots-ninety-nine wants to merge 1 commit into
Conversation
cc5176d to
9986c22
Compare
Specifying `my_param: []` in a node parameters file made the rcl YAML parser emit an `rcl_variant_t` with no type-specific pointer set, since it cannot infer an element type from an empty array. The previous `assert_eq!(num_active, 1)` inside `ParameterValue::from_rcl_variant` turned this into a panic during `executor.create_node`. Change `from_rcl_variant` to return `Option<Self>` and skip ambiguous variants in `resolve_parameter_overrides`, so the node can still start. If the parameter is actually required, the user will get a clearer `DeclarationError::NoValueAvailable` later at `declare_parameter` time. Adds a regression test that loads a YAML file with both a well-formed override and an empty array and verifies the empty entry is dropped while the rest is preserved. Fixes ros2-rust#636
9986c22 to
43a7a7c
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.
Fixes #636.
Problem
A parameter override declared as an empty YAML array crashes the node at
executor.create_nodeinstead of returning a recoverable error.params.yaml:Root cause
ParameterValue::from_rcl_variantexpects exactly one of the nine type-specific pointers onrcl_variant_tto be non-null. For an empty YAML array the rcl YAML parser cannot infer the element type, so it emits a variant with all nine of those pointers null. The function then hitsassert_eq!(num_active, 1)and panics.The same
from_rcl_variantis reached for every parameter override that the node sees, so any node that is started with a parameters file containing a single[]entry will fail to start at all — including nodes that do not even declare that parameter.Fix
Change
from_rcl_variantto returnOption<Self>and returnNonewhen the variant has zero (or, hypothetically, more than one) active fields. The single in-tree caller —resolve_parameter_overridesinoverride_map.rs— now skips overrides whose type could not be determined:Rationale for silently dropping rather than surfacing a brand new error variant:
DeclarationError::NoValueAvailablewill fire atdeclare_parametertime and point at the specific parameter, which is more actionable than a panic during construction.from_rcl_variantpub(crate)and does not add a new variant toRclrsError, so the public API surface is unchanged.The existing in-module test for
from_rcl_variantis adjusted to.expect(...)since the variants it constructs are always well-formed.Verification
Unit tests
Added a regression test
test_resolve_parameter_overrides_skips_empty_arraythat loads:and asserts:
good_intis present with valueInteger(7),empty_arrayis not in the override map,Full
rclrstest suite locally:End-to-end
With the same
params.yamlfrom the bug report, after the fix:Tested on:
cargo-ament-build0.1