Skip to content

Conversation

@leandrolanzieri
Copy link
Contributor

This adds a catch to an exception that might occur when leaving a menu which is not shown by the parent menu. This might occur, for instance, when searching for the symbol of a named choice.

Originally ulfalizer/Kconfiglib#94
See ulfalizer/Kconfiglib#93 for an example of the bug.

@stephanosio
Copy link
Member

Rebased

@tejlmand tejlmand self-assigned this Oct 21, 2025
@tejlmand tejlmand requested review from tejlmand and removed request for jackrosenthal October 21, 2025 09:02
Copy link
Collaborator

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

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

I prefer to handle the situation gracefully, so that other (unrelated) ValueErrors are not caught in the process.

menuconfig.py Outdated
_sel_node_i = _shown.index(_cur_menu)
except ValueError:
# The parent actually does not contain the current menu (e.g., symbol
# search). So we jump to the first node instead.
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not really jumping anywhere.

_sel_node_i is the index of the currently selected node.
That said, pointing to index 0 (first node in menu) should be fine.

menuconfig.py Outdated
Comment on lines 1206 to 1211
try:
_sel_node_i = _shown.index(_cur_menu)
except ValueError:
# The parent actually does not contain the current menu (e.g., symbol
# search). So we jump to the first node instead.
_sel_node_i = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer to have proper handling so that errors are still propagated, so that other ValueErrors are not unexpectedly caught here.

For example like this instead:

Suggested change
try:
_sel_node_i = _shown.index(_cur_menu)
except ValueError:
# The parent actually does not contain the current menu (e.g., symbol
# search). So we jump to the first node instead.
_sel_node_i = 0
if _cur_menu in _shown:
_sel_node_i = _shown.index(_cur_menu)
else:
# `_cur_menu` is not shown, this can happen when an invisible choice is
# extending a choice defined elsewhere. In this case, point to node at index 0.
_sel_node_i = 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I adapted the fix.

@leandrolanzieri leandrolanzieri force-pushed the pr/menuconfig/fix_leaving_menu branch from bdee7ed to 0a132f2 Compare October 21, 2025 12:35
parent = _parent_menu(_cur_menu)
_shown = _shown_nodes(parent)
_sel_node_i = _shown.index(_cur_menu)
_cur_menu = parent
Copy link
Collaborator

@tejlmand tejlmand Oct 21, 2025

Choose a reason for hiding this comment

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

sorry for not noticing in first round, but why are you removing this line ?

    _cur_menu = parent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, sorry that shouldn't be the case. I accidentally removed it in the last change. I'll add it back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

This handles a case of leaving a menu which is not shown by the parent menu.
This might occur, for instance, when searching for the symbol of a named choice,
which is extended by an invisible symbol somewhere else.
@leandrolanzieri leandrolanzieri force-pushed the pr/menuconfig/fix_leaving_menu branch from 0a132f2 to d25a433 Compare October 21, 2025 13:41
@tejlmand tejlmand merged commit 0380400 into zephyrproject-rtos:main Oct 21, 2025
9 checks passed
@leandrolanzieri
Copy link
Contributor Author

Thanks for the review @tejlmand. It's nice to finally see this in.

@leandrolanzieri leandrolanzieri deleted the pr/menuconfig/fix_leaving_menu branch October 22, 2025 06:34
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.

3 participants