Yaml errors no longer fail silently

This commit is contained in:
codemann8
2025-11-08 02:36:28 -06:00
parent a3dd82f467
commit 7016e5afbf
2 changed files with 39 additions and 30 deletions

View File

@@ -577,9 +577,13 @@ class CustomSettings(object):
def load_yaml(path): def load_yaml(path):
try:
if os.path.exists(Path(path)): if os.path.exists(Path(path)):
with open(path, "r", encoding="utf-8") as f: with open(path, "r", encoding="utf-8") as f:
return yaml.load(f, Loader=yaml.SafeLoader) return yaml.load(f, Loader=yaml.SafeLoader)
elif urllib.parse.urlparse(path).scheme in ['http', 'https']: elif urllib.parse.urlparse(path).scheme in ['http', 'https']:
return yaml.load(urllib.request.urlopen(path), Loader=yaml.FullLoader) return yaml.load(urllib.request.urlopen(path), Loader=yaml.FullLoader)
except yaml.YAMLError as e:
error_msg = f"Error parsing YAML file '{path}':\n{str(e)}"
raise ValueError(error_msg) from e

View File

@@ -77,17 +77,23 @@ def bottom_frame(self, parent, args=None):
argsDump['sprite'] = argsDump['sprite'].name argsDump['sprite'] = argsDump['sprite'].name
save_settings(parent, argsDump, "last.json") save_settings(parent, argsDump, "last.json")
try:
guiargs = create_guiargs(parent) guiargs = create_guiargs(parent)
# get default values for missing parameters # get default values for missing parameters
cliargs = ['--multi', str(guiargs.multi)] cliargs = ['--multi', str(guiargs.multi)]
if hasattr(guiargs, 'customizer'): if hasattr(guiargs, 'customizer'):
cliargs.extend(['--customizer', str(guiargs.customizer)]) cliargs.extend(['--customizer', str(guiargs.customizer)])
for k,v in vars(parse_cli(cliargs)).items(): for k,v in vars(parse_cli(cliargs)).items():
if k not in vars(guiargs): if k not in vars(guiargs):
setattr(guiargs, k, v) setattr(guiargs, k, v)
elif type(v) is dict: # use same settings for every player elif type(v) is dict: # use same settings for every player
players = guiargs.multi if len(v) == 0 else len(v) players = guiargs.multi if len(v) == 0 else len(v)
setattr(guiargs, k, {player: getattr(guiargs, k) for player in range(1, players + 1)}) setattr(guiargs, k, {player: getattr(guiargs, k) for player in range(1, players + 1)})
if guiargs.multi == 1 and guiargs.names.endswith("=="):
# allow settings code thru player names entry
guiargs.code[1] = guiargs.names
guiargs.names = ""
argsDump = vars(guiargs) argsDump = vars(guiargs)
needEnemizer = False needEnemizer = False
@@ -102,7 +108,6 @@ def bottom_frame(self, parent, args=None):
needEnemizer = True needEnemizer = True
seeds = [] seeds = []
try:
if guiargs.count is not None and guiargs.seed: if guiargs.count is not None and guiargs.seed:
seed = guiargs.seed seed = guiargs.seed
for _ in range(guiargs.count): for _ in range(guiargs.count):