Skip to content

Be noisy if there are errors while trying to load a team in the server - #978

Open
otizonaizit wants to merge 1 commit into
ASPP:mainfrom
otizonaizit:server_errors
Open

Be noisy if there are errors while trying to load a team in the server#978
otizonaizit wants to merge 1 commit into
ASPP:mainfrom
otizonaizit:server_errors

Conversation

@otizonaizit

Copy link
Copy Markdown
Member

This is a quick fix for #977. I have tried hard to write a test for this, but have failed.

When this PR is applied, and using the setup described in #977 , you get:

pelita-server remote-server  --address 127.0.0.1 --port 10000 --team /tmp/broken.py 
Use --session-key 762890741955 to for the admin API.
Team /tmp/broken.py did not return a filename. Skipping. Error:
Failure while loading team '/tmp/broken.py'
ERROR: No module named 'does_not_exist'
Traceback (most recent call last):
  File "<frozen runpy>", line 203, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/tiziano/git/pelita/pelita/scripts/pelita_player.py", line 392, in <module>
    main()
    ~~~~^^
  File "/usr/lib/python3/dist-packages/click/core.py", line 1514, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/click/core.py", line 1435, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1902, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/lib/python3/dist-packages/click/core.py", line 1298, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/click/core.py", line 853, in invoke
    return callback(*args, **kwargs)
  File "/home/tiziano/git/pelita/pelita/scripts/pelita_player.py", line 357, in cli_check_team
    return check_team(team)
  File "/home/tiziano/git/pelita/pelita/scripts/pelita_player.py", line 365, in check_team
    print(load_team(team).team_name)
          ~~~~~~~~~^^^^^^
  File "/home/tiziano/git/pelita/pelita/scripts/pelita_player.py", line 252, in load_team
    team = load_team_from_module(spec)
  File "/home/tiziano/git/pelita/pelita/scripts/pelita_player.py", line 301, in load_team_from_module
    module = importlib.import_module(modname)
  File "/usr/lib/python3.14/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name, package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1406, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1371, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1342, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 938, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 759, in exec_module
  File "<frozen importlib._bootstrap>", line 491, in _call_with_frames_removed
  File "/tmp/broken.py", line 1, in <module>
    import does_not_exist
ModuleNotFoundError: No module named 'does_not_exist'

which is maybe too verbose, but at least gives a clear hint where to go to fix the problem.

Fixes #977

@Debilski

Copy link
Copy Markdown
Member

Can you make it so that _check_team returns a tuple in either case? So that we don’t have to distinguish the return signature depending on the input value.

Or maybe we just add check=True to subprocess.run and fail hard.

@otizonaizit otizonaizit changed the title Be noisy if there are errors while trying to lead a team in the server Be noisy if there are errors while trying to load a team in the server Aug 27, 2026
@otizonaizit

otizonaizit commented Aug 27, 2026

Copy link
Copy Markdown
Member Author

Can you make it so that _check_team returns a tuple in either case? So that we don’t have to distinguish the return signature depending on the input value.

done

Or maybe we just add check=True to subprocess.run and fail hard.

I didn't dare to do this. I think the right solution is to fix pelita-player check-team to return a non-zero exit status when a team fails to load. This way we can work cleanly and do not have to depend on the presence of strings in stderr/stdout...

@Debilski

Copy link
Copy Markdown
Member

I didn't dare to do this. I think the right solution is to fix pelita-player check-team to return a non-zero exit status when a team fails to load. This way we can work cleanly and do not have to depend on the presence of strings in stderr/stdout...

But that’s what I meant: pelita-player check-team will return 1 on failure and then check=True will raise.

But anyway I am also fine with merging it as is. Thanks.

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.

pelita-server does not report error when a team can not be loaded

2 participants