Skip to content

Commit

Permalink
fix: convert strict JSON errors to warning (#6017)
Browse files Browse the repository at this point in the history
* refactor: move enums to top

needs to be used by realDebugMsg

* feat: selectable debug level in `realDebugmsg`

* fix: make strict violation warning
  • Loading branch information
scarf005 authored Jan 30, 2025
1 parent 496df8f commit 44f0609
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void report_strict_violation( const JsonObject &jo, const std::string &message,
jo.throw_error( message, name );
} catch( const JsonError &err ) {
// And catch the exception so the loading continues like normal.
debugmsg( "(json-error)\n%s", err.what() );
debugmsg_of( DL::Warn, "(json-error)\n%s", err.what() );
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ static repetition_folder rep_folder;
static void output_repetitions( std::ostream &out );

void realDebugmsg( const char *filename, const char *line, const char *funcname,
const std::string &text )
const DL debug_level, const std::string &text )
{
assert( filename != nullptr );
assert( line != nullptr );
Expand All @@ -465,7 +465,7 @@ void realDebugmsg( const char *filename, const char *line, const char *funcname,
captured += text;
} else {
if( !rep_folder.test( filename, line, funcname, text ) ) {
*detail::realDebugLog( DL::Error, DC::DebugMsg, filename, line, funcname ) << text;
*detail::realDebugLog( debug_level, DC::DebugMsg, filename, line, funcname ) << text;
rep_folder.set( filename, line, funcname, text );
} else {
rep_folder.increment_count();
Expand Down
128 changes: 65 additions & 63 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,69 +67,6 @@ template<typename E> class enum_bitset;
#define __FUNCTION_NAME__ __func__
#endif

/**
* Debug message of level DL::Error and class DC::DebugMsg, also includes the source
* file name and line, uses varg style arguments, the first argument must be
* a printf style format string.
*/
#define debugmsg(...) realDebugmsg(__FILE__, STRING(__LINE__), __FUNCTION_NAME__, __VA_ARGS__)

// Don't use this, use debugmsg instead.
void realDebugmsg( const char *filename, const char *line, const char *funcname,
const std::string &text );
template<typename ...Args>
inline void realDebugmsg( const char *const filename, const char *const line,
const char *const funcname, const char *const mes, Args &&... args )
{
return realDebugmsg( filename, line, funcname, string_format( mes,
std::forward<Args>( args )... ) );
}

// A fatal error for use in constexpr functions
// This exists for compatibility reasons. On gcc 5.3 we need a
// different implementation that is messier.
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67371
// Pass a placeholder return value to be used on gcc 5.3 (it won't
// actually be returned, it's just needed for the type), and then
// args as if to debugmsg for the remaining args.
#if defined(__GNUC__) && __GNUC__ < 6
#define constexpr_fatal(ret, ...) \
do { return false ? ( ret ) : ( abort(), ( ret ) ); } while(false)
#else
#define constexpr_fatal(ret, ...) \
do { debugmsg(__VA_ARGS__); abort(); } while(false)
#endif

/**
* Used to generate game report information.
*/
namespace game_info
{
/** Return the name of the current operating system.
*/
std::string operating_system();
/** Return a detailed version of the operating system; e.g. "Ubuntu 18.04" or "(Windows) 10 1809".
*/
std::string operating_system_version();
/** Return the "bitness" of the game (not necessarily of the operating system); either: 64, 32 or nullopt.
*/
std::optional<int> bitness();
/** Return the "bitness" string of the game (not necessarily of the operating system); either: 64-bit, 32-bit or Unknown.
*/
std::string bitness_string();
/** Return the game version, as in the entry screen.
*/
std::string game_version();
/** Return the underlying graphics version used by the game; either Tiles or Curses.
*/
std::string graphics_version();
/** Return a list of the loaded mods, including the mod full name and its id name in brackets, e.g. "Dark Days Ahead [dda]".
*/
std::string mods_loaded();
/** Generate a game report, including the information returned by all of the other functions.
*/
std::string game_report();
} // namespace game_info

// Enumerations {{{1
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -204,6 +141,71 @@ enum class DebugOutput {
file,
};

#define debugmsg_of(debug_level, ...) realDebugmsg(__FILE__, STRING(__LINE__), __FUNCTION_NAME__, debug_level, __VA_ARGS__)

/**
* Debug message of level DL::Error and class DC::DebugMsg, also includes the source
* file name and line, uses varg style arguments, the first argument must be
* a printf style format string.
*/
#define debugmsg(...) debugmsg_of(DL::Error, __VA_ARGS__)
// Don't use this, use debugmsg instead.
void realDebugmsg( const char *filename, const char *line, const char *funcname,
const DL debug_level, const std::string &text );
template<typename ...Args>
inline void realDebugmsg( const char *const filename, const char *const line,
const char *const funcname, const DL debug_level, const char *const mes, Args &&... args )
{
return realDebugmsg( filename, line, funcname, debug_level, string_format( mes,
std::forward<Args>( args )... ) );
}

// A fatal error for use in constexpr functions
// This exists for compatibility reasons. On gcc 5.3 we need a
// different implementation that is messier.
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67371
// Pass a placeholder return value to be used on gcc 5.3 (it won't
// actually be returned, it's just needed for the type), and then
// args as if to debugmsg for the remaining args.
#if defined(__GNUC__) && __GNUC__ < 6
#define constexpr_fatal(ret, ...) \
do { return false ? ( ret ) : ( abort(), ( ret ) ); } while(false)
#else
#define constexpr_fatal(ret, ...) \
do { debugmsg(__VA_ARGS__); abort(); } while(false)
#endif

/**
* Used to generate game report information.
*/
namespace game_info
{
/** Return the name of the current operating system.
*/
std::string operating_system();
/** Return a detailed version of the operating system; e.g. "Ubuntu 18.04" or "(Windows) 10 1809".
*/
std::string operating_system_version();
/** Return the "bitness" of the game (not necessarily of the operating system); either: 64, 32 or nullopt.
*/
std::optional<int> bitness();
/** Return the "bitness" string of the game (not necessarily of the operating system); either: 64-bit, 32-bit or Unknown.
*/
std::string bitness_string();
/** Return the game version, as in the entry screen.
*/
std::string game_version();
/** Return the underlying graphics version used by the game; either Tiles or Curses.
*/
std::string graphics_version();
/** Return a list of the loaded mods, including the mod full name and its id name in brackets, e.g. "Dark Days Ahead [dda]".
*/
std::string mods_loaded();
/** Generate a game report, including the information returned by all of the other functions.
*/
std::string game_report();
} // namespace game_info

/** Initializes the debugging system, called exactly once from main() */
void setupDebug( DebugOutput );
/** Opposite of setupDebug, shuts the debugging system down. */
Expand Down

0 comments on commit 44f0609

Please sign in to comment.