Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Deduplicate console exception output #4036

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Zannick
Copy link

@Zannick Zannick commented Oct 8, 2024

What is this fixing or adding?

When running Generate.py, uncaught exceptions are logged once to a file and twice to the console due to keeping the original excepthook. We can avoid this by filtering the file log out of the stream handler, and letting the original excepthook print the traceback.

How was this tested?

Created a player yaml file with

Noita:
  progression_balancing:
    garbl: 10

and ran python Generate.py --skip_output.

Results

Before
Uncaught exception
Traceback (most recent call last):
  File "Documents\GitHub\Archipelago\Generate.py", line 417, in handle_option
    player_option = option.from_any(get_choice(option_key, game_weights))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Documents\GitHub\Archipelago\Options.py", line 732, in from_any
    return cls.from_text(str(data))
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "Documents\GitHub\Archipelago\Options.py", line 770, in from_text
    return super().from_text(text)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "Documents\GitHub\Archipelago\Options.py", line 687, in from_text
    return cls(int(text))
               ^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'garbl'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "Documents\GitHub\Archipelago\Generate.py", line 194, in main
    tuple(roll_settings(yaml, args.plando) for yaml in weights_cache[path])
  File "Documents\GitHub\Archipelago\Generate.py", line 194, in <genexpr>
    tuple(roll_settings(yaml, args.plando) for yaml in weights_cache[path])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Documents\GitHub\Archipelago\Generate.py", line 487, in roll_settings
    handle_option(ret, game_weights, option_key, option, plando_options)
  File "Documents\GitHub\Archipelago\Generate.py", line 422, in handle_option
    raise Options.OptionError(f"Error generating option {option_key} in {ret.game}") from e
Options.OptionError: Error generating option progression_balancing in Noita

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "Documents\GitHub\Archipelago\Generate.py", line 530, in <module>
    erargs, seed = main()
                   ^^^^^^
  File "Documents\GitHub\Archipelago\Generate.py", line 213, in main
    raise ValueError(f"File {path} is invalid. Please fix your yaml.") from e
ValueError: File Noita.yaml is invalid. Please fix your yaml.
Traceback (most recent call last):
  File "Documents\GitHub\Archipelago\Generate.py", line 417, in handle_option
    player_option = option.from_any(get_choice(option_key, game_weights))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Documents\GitHub\Archipelago\Options.py", line 732, in from_any
    return cls.from_text(str(data))
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "Documents\GitHub\Archipelago\Options.py", line 770, in from_text
    return super().from_text(text)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "Documents\GitHub\Archipelago\Options.py", line 687, in from_text
    return cls(int(text))
               ^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'garbl'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "Documents\GitHub\Archipelago\Generate.py", line 194, in main
    tuple(roll_settings(yaml, args.plando) for yaml in weights_cache[path])
  File "Documents\GitHub\Archipelago\Generate.py", line 194, in <genexpr>
    tuple(roll_settings(yaml, args.plando) for yaml in weights_cache[path])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Documents\GitHub\Archipelago\Generate.py", line 487, in roll_settings
    handle_option(ret, game_weights, option_key, option, plando_options)
  File "Documents\GitHub\Archipelago\Generate.py", line 422, in handle_option
    raise Options.OptionError(f"Error generating option {option_key} in {ret.game}") from e

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "Documents\GitHub\Archipelago\Generate.py", line 530, in <module>
    erargs, seed = main()
                   ^^^^^^
  File "Documents\GitHub\Archipelago\Generate.py", line 213, in main
    raise ValueError(f"File {path} is invalid. Please fix your yaml.") from e
ValueError: File Noita.yaml is invalid. Please fix your yaml.
Press enter to close.
After
Traceback (most recent call last):
  File "Documents\GitHub\Archipelago\Generate.py", line 417, in handle_option
    player_option = option.from_any(get_choice(option_key, game_weights))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Documents\GitHub\Archipelago\Options.py", line 732, in from_any
    return cls.from_text(str(data))
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "Documents\GitHub\Archipelago\Options.py", line 770, in from_text
    return super().from_text(text)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "Documents\GitHub\Archipelago\Options.py", line 687, in from_text
    return cls(int(text))
               ^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'garbl'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "Documents\GitHub\Archipelago\Generate.py", line 194, in main
    tuple(roll_settings(yaml, args.plando) for yaml in weights_cache[path])
  File "Documents\GitHub\Archipelago\Generate.py", line 194, in <genexpr>
    tuple(roll_settings(yaml, args.plando) for yaml in weights_cache[path])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Documents\GitHub\Archipelago\Generate.py", line 487, in roll_settings
    handle_option(ret, game_weights, option_key, option, plando_options)
  File "Documents\GitHub\Archipelago\Generate.py", line 422, in handle_option
    raise Options.OptionError(f"Error generating option {option_key} in {ret.game}") from e
Options.OptionError: Error generating option progression_balancing in Noita

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "Documents\GitHub\Archipelago\Generate.py", line 530, in <module>
    erargs, seed = main()
                   ^^^^^^
  File "Documents\GitHub\Archipelago\Generate.py", line 213, in main
    raise ValueError(f"File {path} is invalid. Please fix your yaml.") from e
ValueError: File Noita.yaml is invalid. Please fix your yaml.
Press enter to close.

When running Generate.py, uncaught exceptions are logged once to a file and twice to the console due to keeping the original excepthook. We can avoid this by filtering the file log out of the stream handler.
@github-actions github-actions bot added affects: core Issues/PRs that touch core and may need additional validation. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. labels Oct 8, 2024
@Exempt-Medic Exempt-Medic added the is: enhancement Issues requesting new features or pull requests implementing new features. label Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: core Issues/PRs that touch core and may need additional validation. is: enhancement Issues requesting new features or pull requests implementing new features. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants