Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
SUMMARY: Infrastructure "Stricter json parsing; errors will occur in more places. This may cause some mods to fail to load"
Purpose of change
Our json parsing code is very permissive, and quite a lot of errors can go unnoticed. It will help content designers if we detect more errors, especially if they're detected in CI.
Describe the solution
Be stricter about parsing in the following way:
Add a
bool throw_on_error
to allJsonIn::read
functions. Iftrue
, this causes them to throw an exception on error rather than just returningfalse
. The exception is thrown via the usualJsonIn::error
function that provides a useful error message.This
bool
defaults tofalse
, but defaults totrue
for calls viaJsonObject::read
, which constitute the bulk of our json reading of game data files. Those functions also gained a new parameter so you can override back to non-throwing if you wish.This caught some problems, which I've fixed in this PR:
refuel_fires
should be a boolean, not a string.damage_instance
needs to be able to load from a json array as well as a json object.JsonObject
member, give a different error message depending on whether any member with that name was present.Describe alternatives you've considered
I had to choose new values for the dialogue opinion changes. I assumed that they were intended to be random selections from a range, so I took the midpoint of the range, and rounded to the nearest integer (rounding in the direction more favourable to the player). Then removed the ones that were just zero after that. @I-am-Erk might want to make further changes depending on the original intention.
Additional context
I want to further increase json parsing strictness. This is just the first step.
I tested with many of the included mods, but not all of them, so this might break some of the core mods, and it could certainly break third party mods. But usually the fix is pretty obvious.