Source.Python icon indicating copy to clipboard operation
Source.Python copied to clipboard

Menu KeyError

Open Frag1337 opened this issue 2 years ago • 3 comments

Hi, my console is ocassionaly filled with these. Not sure how to reproduce that. Maybe it has something to do with sourcemod menu's clashing?

Traceback (most recent call last):
  File "/home/cssserver1/serverfiles/cstrike/addons/source-python/packages/source-python/commands/auth.py", line 44, in __call__
    return self.callback(*args)
  File "/home/cssserver1/serverfiles/cstrike/addons/source-python/packages/source-python/menus/queue.py", line 267, in _menuselect_callback
    _radio_queues[index]._select(choice)
  File "/home/cssserver1/serverfiles/cstrike/addons/source-python/packages/source-python/menus/queue.py", line 126, in _select
    next_menu = active_menu._select(self._index, choice)
  File "/home/cssserver1/serverfiles/cstrike/addons/source-python/packages/source-python/menus/radio.py", line 113, in _select
    self._player_pages[player_index].options[choice_index])
KeyError: 3

Frag1337 avatar Jul 18 '23 18:07 Frag1337

Yes, this is likely a conflict with another server plugin. Could be difficult to fix.

Ayuto avatar Jul 18 '23 18:07 Ayuto

I get those errors randomly aswell, even i though only have installed sp and only use sp plugins i made

srpg avatar Jul 18 '23 19:07 srpg

These happens when the menuselect command is issued directly through the console (e.g. through a bind) with an option that is not valid for the current page. For example:

from menus import *
from players.entity import *

SimpleMenu(['...',]).send(1)
Player(1).client_command('menuselect 3', True)

"""
[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\commands\auth.py", line 44, in __call__
    return self.callback(*args)
  File "..\addons\source-python\packages\source-python\menus\queue.py", line 267, in _menuselect_callback
    _radio_queues[index]._select(choice)
  File "..\addons\source-python\packages\source-python\menus\queue.py", line 126, in _select
    next_menu = active_menu._select(self._index, choice)
  File "..\addons\source-python\packages\source-python\menus\radio.py", line 113, in _select
    self._player_pages[player_index].options[choice_index])

KeyError: 3
"""

Passing no value is also producing an error:

from menus import *
from players.entity import *

SimpleMenu(['...',]).send(1)
Player(1).client_command('menuselect', True)

"""
[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\commands\auth.py", line 44, in __call__
    return self.callback(*args)
  File "..\addons\source-python\packages\source-python\menus\queue.py", line 265, in _menuselect_callback
    index, choice = _validate_selection(command, index, VALID_CHOICES)
  File "..\addons\source-python\packages\source-python\menus\queue.py", line 221, in _validate_selection
    choice = int(command[1])

IndexError: Index out of range.
"""

https://github.com/Source-Python-Dev-Team/Source.Python/commit/f3272be05dfae8a9665311bfdd628416ce51b8d4 addresses those contexts.

jordanbriere avatar Jul 18 '23 20:07 jordanbriere