Source-Python-Dev-Team / Source.Python

This plugin aims to use boost::python and create an easily accessible wrapper around the Source Engine API for scripter use.
http://forums.sourcepython.com
GNU General Public License v3.0
163 stars 31 forks source link

Menu KeyError #487

Open Frag1337 opened 1 year ago

Frag1337 commented 1 year ago

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
Ayuto commented 1 year ago

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

srpg commented 1 year ago

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

jordanbriere commented 1 year ago

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.