Skip to content

Commit c8315e4

Browse files
Raise error on bad enum values
1 parent 1c81cfb commit c8315e4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

rlbot/config.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
from rlbot.utils.os_detector import CURRENT_OS, OS
88

99

10+
class ConfigParsingException(Exception):
11+
pass
12+
13+
1014
def __parse_enum(table: dict, key: str, enum: Any, default: int = 0) -> Any:
1115
if key not in table:
1216
return enum(default)
@@ -15,9 +19,7 @@ def __parse_enum(table: dict, key: str, enum: Any, default: int = 0) -> Any:
1519
if str(enum(i)).split('.')[-1].lower() == table[key].lower():
1620
return enum(i)
1721
except ValueError:
18-
logger.error(f"Invalid value '{table[key]}' for key '{key}'. "
19-
f"Using default '{str(enum(default)).split('.')[-1]}' instead.")
20-
return enum(default)
22+
raise ConfigParsingException(f"Invalid value \"{table[key]}\" for key \"{key}\".")
2123

2224

2325
def load_match_config(config_path: Path | str) -> flat.MatchConfiguration:
@@ -42,8 +44,7 @@ def load_match_config(config_path: Path | str) -> flat.MatchConfiguration:
4244
except ValueError:
4345
team = {"blue": 0, "orange": 1}.get(team.lower())
4446
if team is None or team not in [0, 1]:
45-
logger.error(f"Invalid team '{car_table.get("team")}' for player {len(players)}. "
46-
"Using default team 0 instead.")
47+
raise ConfigParsingException(f"Invalid team \"{car_table.get("team")}\" for player {len(players)}.")
4748

4849
loadout_file = car_table.get("loadout_file")
4950
skill = __parse_enum(car_table, "skill", flat.PsyonixSkill, int(flat.PsyonixSkill.AllStar))
@@ -60,8 +61,7 @@ def load_match_config(config_path: Path | str) -> flat.MatchConfiguration:
6061
logger.warning("PartyMember player type is not supported yet.")
6162
variety, use_config = flat.PartyMember, False
6263
case t:
63-
logger.error(f"Invalid player type '{t}' for player {len(players)}. Using default 'rlbot' instead.")
64-
variety, use_config = flat.CustomBot(), True
64+
raise ConfigParsingException(f"Invalid player type \"{t}\" for player {len(players)}.")
6565

6666
if use_config and car_config is not None:
6767
abs_config_path = (config_path.parent / car_config).resolve()

0 commit comments

Comments
 (0)