Skip to content

fix(xtce_parser): crash on BaseContainer inside CommandContainer#3377

Merged
jmthomas merged 1 commit into
OpenC3:mainfrom
jwalters2:fix/xtce-base-container-command-crash
May 14, 2026
Merged

fix(xtce_parser): crash on BaseContainer inside CommandContainer#3377
jmthomas merged 1 commit into
OpenC3:mainfrom
jwalters2:fix/xtce-base-container-command-crash

Conversation

@jwalters2
Copy link
Copy Markdown
Contributor

Summary

  • Bug: xtce_handle_base_container clones TM SequenceContainer items into a command packet without setting range or default. These fields are nil because set_min_max_default skips non-COMMAND items during TM processing. Later, to_config(:COMMAND)calculate_range() calls range.first on nil, raising NoMethodError.
  • Fix: Add set_item_range_and_default to populate range and default on cloned items based on their bit_size and data_type when the target packet is a command.
  • Trigger: Any XTCE file using BaseContainer containerRef="..." inside a CommandContainer (standard XTCE v1.3 pattern for CCSDS header inheritance in telecommands).

Reproduction

Minimal XTCE with an abstract SequenceContainer (CCSDS_Header) referenced via BaseContainer from a CommandContainer:

<xtce:CommandContainer name="CMD1_Container">
  <xtce:EntryList>
    <xtce:ArgumentRefEntry argumentRef="payload"/>
  </xtce:EntryList>
  <xtce:BaseContainer containerRef="CCSDS_Header">
    <xtce:RestrictionCriteria>
      <xtce:ComparisonList>
        <xtce:Comparison parameterRef="apid" value="100"/>
      </xtce:ComparisonList>
    </xtce:RestrictionCriteria>
  </xtce:BaseContainer>
</xtce:CommandContainer>
NoMethodError: undefined method 'first' for nil:NilClass
  openc3/lib/openc3/packets/packet_item.rb:328:in 'calculate_range'

Test plan

  • Added 3 RSpec tests in xtce_parser_spec.rb covering:
    • Cloned TM items get correct range, default, bit_size, data_type in command packet
    • RestrictionCriteria Comparisons correctly set id_value on inherited items
    • to_config(:COMMAND) does not crash
  • All 18 tests pass (15 existing + 3 new), zero regressions

🤖 Generated with Claude Code

…nd packets

When a CommandContainer uses BaseContainer to reference a TM
SequenceContainer (e.g., CCSDS_Header), xtce_handle_base_container
clones TM items into the command packet. These cloned items have
range=nil and default=nil because set_min_max_default skips non-COMMAND
items during TM processing. This causes a NoMethodError on range.first
in calculate_range when to_config(:COMMAND) is called.

Add set_item_range_and_default to populate range and default on cloned
items based on their bit_size and data_type when the target packet is
a command.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

❌ Patch coverage is 58.82353% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.80%. Comparing base (a44a0a6) to head (42c826e).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
openc3/lib/openc3/packets/parsers/xtce_parser.rb 58.82% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3377      +/-   ##
==========================================
+ Coverage   78.76%   78.80%   +0.04%     
==========================================
  Files         687      687              
  Lines       57263    57282      +19     
  Branches      728      728              
==========================================
+ Hits        45103    45142      +39     
+ Misses      12082    12062      -20     
  Partials       78       78              
Flag Coverage Δ
python 80.03% <ø> (+0.01%) ⬆️
ruby-api 81.67% <ø> (-0.59%) ⬇️
ruby-backend 82.24% <58.82%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jmthomas
Copy link
Copy Markdown
Member

@jwalters2 thanks for the fix!

@jmthomas jmthomas self-requested a review May 14, 2026 22:01
@jmthomas jmthomas merged commit 086ed47 into OpenC3:main May 14, 2026
31 of 33 checks passed
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