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

Abort starting / continuing a game upon any kind of error from loading JSON game data. #18137

Merged
merged 7 commits into from Aug 29, 2016

Conversation

Projects
None yet
2 participants
@BevapDin
Copy link
Contributor

commented Aug 28, 2016

This kind of relates to #18130. If the game encounters an error while loading the JSON data, it cancels loading the game data (items etc.), but otherwise continues loading / starting the actual game. This leads to a various errors about missing definitions.

The PR changes the logic to abort starting / continuing a game and going back to the main menu.

The "load" functions in class game now throw an exception (or simply propagate the exception throw from within further function calls). Callers catch those exceptions:

  • dump_stats reports them via std::cerr (as the curses system is not initialized there, see surrounding code) and returns immediately,
  • same for game::check_mod_data,
  • same for code in tests/.
  • game::quickload reports via debugmsg, technically the program should just exit as the game may be in any invalid state, but the user could try to fix the problem and do another quickload.
  • Code in main_menu.cpp will just abort loading/starting a game. This should be safe, users can start a new game / load another game without leaving the program.

To test this, add some errors to the JSON files and try to start/load a game. It should print a debug message and put you back into the menu.


This is technically an alternative to #18136, it fixes the "When you try to play the game, it throws what must be hundreds of errors at you, saying it can't find tons and tons of stuff" issue.

But #18136 is not an alternative to this PR. #18136 won't fix the main problem: the program allows you to start a game with faulty JSON data. #18136 allows one to reach the actual game despite redundant JSON values.

BevapDin added some commits Aug 28, 2016

Don't catch exceptions in game::load_data_from_dir
Instead let them bubble up the call stack and catch them (for now) in the caller.
Don't catch exceptions in game::load_core_data
Instead let them bubble up the call stack and catch them (for now) in the caller.
Don't catch exceptions in game::setup
Instead let them bubble up the call stack and catch them (for now) in the caller.
Cancel load / starting a new game when game::setup fails.
Instead of continuing with incomplete game data.
Don't catch exceptions in game::load_world_modfiles
Instead let them bubble up the call stack and catch them (for now) in the caller.
Make game::load_core_data protected
Doesn't need to be public.
Combine several try-catch blocks into one.
No point in having them separate, the code in the later block depends on the code in the former block having succeeded.

@Coolthulhu Coolthulhu self-assigned this Aug 29, 2016

@Coolthulhu Coolthulhu merged commit 64fcaa7 into CleverRaven:master Aug 29, 2016

1 check passed

default This has been rescheduled for testing as the 'master' branch has been updated.

@BevapDin BevapDin deleted the BevapDin:iki branch Aug 29, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.