Fix WiFi network selection in TUI prompt#4566
Conversation
TableSelectionScreen returns the selected network in Result._item, but the check on line 136 only tested Result._data (always None for single-select). This caused every selection to fall through to the "No wifi networks found" error path. Fixes archlinux#4564
| match result.type_: | ||
| case ResultType.Selection: | ||
| if not result.has_data(): | ||
| if not result.has_value() and not result.has_data(): |
There was a problem hiding this comment.
There is no reason to check this at all here as on a selection there should always be a value present, so it can altogether be simplified to
case ResultType.Selection:
network = result.get_value()
There was a problem hiding this comment.
Good point - for the normal flow where a user picks a row, _item is always set. However, _put_data_to_table dismisses with a bare Result(ResultType.Selection) (no _item, no _data) when the item list is empty. In that case get_value() would hit the assertion.
Or am I wrong?..
There was a problem hiding this comment.
I think there's actually another bug in the function
async def get_wifi_networks() -> MenuItemGroup:
debug('Scanning Wifi networks')
result = self._wpa_cli('scan', wifi_iface)
if not result.success:
debug(f'Failed to scan wifi networks: {result.error}')
return MenuItemGroup([])
await sleep(5)
wifi_networks = self._get_scan_results(wifi_iface)
items = [MenuItem(network.ssid, value=network) for network in wifi_networks]
return MenuItemGroup(items)
If that returns no results with MenuItemGroup([]) then the whole TUI blows up, which I think is the case you described?
There was a problem hiding this comment.
Hm.. Maybe you're right, let me think...
There was a problem hiding this comment.
@svartkanin
You're right, I moved the scan logic out of the callback into a separate _scan_wifi() method. Now the empty result is handled before TableSelectionScreen, so MenuItemGroup([]) never happens. The Selection branch is simplified to just get_value(). See 93092a7 - what do you think?
Move wifi scanning out of the TableSelectionScreen callback to avoid MenuItemGroup([]) ValueError when no networks are found. The empty result is now handled before the selection screen, and the Selection branch is simplified to a direct get_value() call.
TableSelectionScreen returns selected item in Result._item, but wifi_handler.py checked only Result._data (via has_data()), which is always None for single-select mode.
Every WiFi network selection fell through to the "No wifi networks found" error path, making WiFi setup completely broken.
Fix: check both has_value() and has_data() before treating the result as empty
Fixes #4564