Skip to content

Throw an exception for duplicate interface port names - #694

Merged
mkorbel1 merged 1 commit into
intel:mainfrom
aishasalim:fix/interface-duplicate-port-exception
Aug 6, 2026
Merged

Throw an exception for duplicate interface port names#694
mkorbel1 merged 1 commit into
intel:mainfrom
aishasalim:fix/interface-duplicate-port-exception

Conversation

@aishasalim

Copy link
Copy Markdown
Contributor

Fixes #514.

Interface._setPort caught a port name that already exists on the interface with an assert:

assert(!_ports.containsKey(portName),
    'Port named $portName already exists on this interface.');

Asserts are stripped in release mode, so outside of tests the duplicate silently replaced the earlier entry in _ports and the interface ended up carrying a port the caller never intended.

This replaces it with a DuplicatePortNameException, a new RohdException alongside the existing InterfaceNameException and InterfaceTypeException in lib/src/exceptions/interface/, so the collision is reported in every build mode.

Testing

New test in interface_test.dart builds an interface that declares the same port name twice and expects the exception. Confirmed it fails against unmodified interface.dart first — it threw _AssertionError rather than a RohdException — so the test genuinely covers the change.

Full gate locally: dart test 1320 passed, dart format 0 changed, dart analyze --fatal-infos clean, dart doc 0 warnings and 0 errors, pana 160/160.

Note

This is a behavior change for release-mode builds that were unknowingly relying on the silent overwrite — that is the point of the issue, but flagging it since it could surface in downstream code. Happy to rename the exception or reword the message if you would prefer something different.

`Interface._setPort` guarded against a port name colliding with one
already on the interface using an `assert`, so the check was stripped in
release mode and the second port silently replaced the first in `_ports`.

Replace it with a `DuplicatePortNameException`, a new `RohdException`
alongside the existing interface name and type exceptions, so the
collision is reported in every build mode.

Fixes intel#514

@mkorbel1 mkorbel1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you for the contribution!

@mkorbel1
mkorbel1 merged commit 9020a95 into intel:main Aug 6, 2026
3 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.

Interface._setPort assertion should be an exception

2 participants