Generate: improve error message for missing game (#1857)

---------

Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
This commit is contained in:
Fabian Dill 2023-06-23 10:17:35 +02:00 committed by GitHub
parent f3c788d0cc
commit 78b981228a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 26 deletions

View File

@ -447,6 +447,11 @@ def roll_settings(weights: dict, plando_options: PlandoOptions = PlandoOptions.b
raise Exception(f"Option {option_key} has to be in a game's section, not on its own.") raise Exception(f"Option {option_key} has to be in a game's section, not on its own.")
ret.game = get_choice("game", weights) ret.game = get_choice("game", weights)
if ret.game not in AutoWorldRegister.world_types:
picks = Utils.get_fuzzy_results(ret.game, AutoWorldRegister.world_types, limit=1)[0]
raise Exception(f"No world found to handle game {ret.game}. Did you mean '{picks[0]}' ({picks[1]}% sure)? "
f"Check your spelling or installation of that world.")
if ret.game not in weights: if ret.game not in weights:
raise Exception(f"No game options for selected game \"{ret.game}\" found.") raise Exception(f"No game options for selected game \"{ret.game}\" found.")
@ -461,7 +466,6 @@ def roll_settings(weights: dict, plando_options: PlandoOptions = PlandoOptions.b
for option_key, option in Options.common_options.items(): for option_key, option in Options.common_options.items():
setattr(ret, option_key, option.from_any(get_choice(option_key, weights, option.default))) setattr(ret, option_key, option.from_any(get_choice(option_key, weights, option.default)))
if ret.game in AutoWorldRegister.world_types:
for option_key, option in world_type.option_definitions.items(): for option_key, option in world_type.option_definitions.items():
handle_option(ret, game_weights, option_key, option, plando_options) handle_option(ret, game_weights, option_key, option, plando_options)
for option_key, option in Options.per_game_common_options.items(): for option_key, option in Options.per_game_common_options.items():
@ -485,8 +489,6 @@ def roll_settings(weights: dict, plando_options: PlandoOptions = PlandoOptions.b
)) ))
elif ret.game == "A Link to the Past": elif ret.game == "A Link to the Past":
roll_alttp_settings(ret, game_weights, plando_options) roll_alttp_settings(ret, game_weights, plando_options)
else:
raise Exception(f"Unsupported game {ret.game}")
return ret return ret

View File

@ -92,7 +92,7 @@ def roll_options(options: Dict[str, Union[dict, str]],
rolled_results[f"{filename}/{i + 1}"] = roll_settings(yaml_data, rolled_results[f"{filename}/{i + 1}"] = roll_settings(yaml_data,
plando_options=plando_options) plando_options=plando_options)
except Exception as e: except Exception as e:
results[filename] = f"Failed to generate mystery in {filename}: {e}" results[filename] = f"Failed to generate options in {filename}: {e}"
else: else:
results[filename] = True results[filename] = True
return results, rolled_results return results, rolled_results