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

Added debug options for reporting unvisited json members #35065

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <utility>

#include "cata_utility.h"
#include "options.h"

// JSON parsing and serialization tools for Cataclysm-DDA.
// For documentation, see the included header, json.h.
Expand Down Expand Up @@ -99,14 +100,17 @@ JsonObject::JsonObject( JsonIn &j )
void JsonObject::finish()
{
#ifndef CATA_IN_TOOL
if( report_unvisited_members && !reported_unvisited_members && !std::uncaught_exception() ) {
if( report_unvisited_members && !reported_unvisited_members && !std::uncaught_exception() &&
get_option<bool>( "JSON_REPORT_UNVISITED_MEMBERS" ) ) {
reported_unvisited_members = true;
for( const std::pair<std::string, int> &p : positions ) {
const std::string &name = p.first;
if( !visited_members.count( name ) && !string_starts_with( name, "//" ) &&
name != "blueprint" ) {
dbg( D_ERROR ) << "Failed to visit member '" << name << "' in JsonObject at "
<< jsin->line_number( start ) << ":\n" << str() << std::endl;
<< ( get_option<bool>( "JSON_POSITION_OF_UNVISITED_MEMBERS" ) ?
jsin->line_number( start ) : "line 0:0,0" )
<< ":\n" << str() << std::endl;
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,20 @@ void options_manager::add_options_debug()
translate_marker( "If true, file path names are going to be transcoded from system encoding to UTF-8 when reading and will be transcoded back when writing. Mainly for CJK Windows users." ),
true
);

add( "JSON_REPORT_UNVISITED_MEMBERS", "debug",
translate_marker( "Report unvisited json members" ),
translate_marker( "If true, unvisited json members will be reported to debug.log when loading json files." ),
false
);
add( "JSON_POSITION_OF_UNVISITED_MEMBERS", "debug",
translate_marker( "Show position of unvisited json members" ),
translate_marker( "If true, position of unvisited json members will be reported to debug.log when loading json files. Hinders performance A LOT!" ),
false
);

get_option( "JSON_POSITION_OF_UNVISITED_MEMBERS" ).setPrerequisite( "JSON_REPORT_UNVISITED_MEMBERS" );

}

void options_manager::add_options_world_default()
Expand Down