Skip to content

[Sim] add error levels to error() messages #10061

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

Open
wants to merge 1 commit into
base: thewarwithin
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions engine/player/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ void player_t::init()
// Validate current fight style is supported by the actor's module.
if ( !validate_fight_style( sim->fight_style ) )
{
sim->error( "{} does not support fight style {}, results may be unreliable.", *this,
sim->error( error_level_e::FIGHT_STYLE, "{} does not support fight style {}, results may be unreliable.", *this,
util::fight_style_string( sim->fight_style ) );
}

Expand Down Expand Up @@ -2711,7 +2711,8 @@ static std::string generate_traits_hash( player_t* player )
static void parse_traits_hash( const std::string& talents_str, player_t* player )
{
auto do_error = [ player, &talents_str ]( std::string_view msg = {} ) {
player->sim->error( "Player {} has invalid talent tree hash {}{}{}", player->name(), talents_str, msg.empty() ? "" : ": ", msg );
player->sim->error( error_level_e::TALENT_HASH, "Player {} has invalid talent tree hash {}{}{}", player->name(),
talents_str, msg.empty() ? "" : ": ", msg );
};

if ( talents_str.find_first_not_of( base64_char ) != std::string::npos )
Expand Down
8 changes: 7 additions & 1 deletion engine/report/json/report_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,13 @@ void print_json_pretty( FILE* o, const sim_t& sim, const ::report::json::report_

if ( !sim.error_list.empty() )
{
root[ "notifications" ] = sim.error_list;
auto node = root[ "notifications" ];
node.make_array();
range::for_each( sim.error_list, [ & ]( const auto& error ) {
auto entry = node.add();
entry[ "level" ] = error.first;
entry[ "message" ] = error.second;
} );
}

std::array<char, 16384> buffer;
Expand Down
2 changes: 1 addition & 1 deletion engine/report/report_html_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ void print_html_errors( report::sc_html_stream& os, const sim_t& sim )
os << "<pre class=\"section section-open\" style=\"color: black; background-color: white; font-weight: bold;\">\n";

for ( const auto& error : sim.error_list )
os << util::encode_html( error ) << "\n";
os.format( "{}: {}\n", util::error_level_string( error.first ), error.second );

os << "</pre>\n\n";
}
Expand Down
11 changes: 11 additions & 0 deletions engine/sc_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1475,3 +1475,14 @@ enum trait_definition_op : int
TRAIT_OP_SET,
TRAIT_OP_MUL
};

// sim_t::error() severity level
enum error_level_e : unsigned short
{
TRIVIAL = 0,
MODERATE,
SEVERE,
FIGHT_STYLE = 10,
TALENT_HASH,
WORK_IN_PROGRESS
};
10 changes: 5 additions & 5 deletions engine/sim/sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3143,13 +3143,13 @@ void sim_t::do_pause()
}
}

void sim_t::set_error(std::string error)
void sim_t::set_error( error_level_e level, std::string error )
{
util::replace_all( error, "\n", "" );
fmt::print( stderr, "{}\n", error );
std::fflush( stderr );
util::replace_all( error, "\n", "" );
fmt::print( stderr, "{}\n", error );
std::fflush( stderr );

error_list.push_back( std::move( error ) );
error_list.emplace_back( level, std::move( error ) );
}

/// merge sims
Expand Down
27 changes: 23 additions & 4 deletions engine/sim/sim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ struct sim_t : private sc_thread_t
std::vector<report::json::report_configuration_t> json_reports;
std::string output_file_str, html_file_str, json_file_str;
std::string reforge_plot_output_file_str;
std::vector<std::string> error_list;
std::vector<std::pair<error_level_e, std::string>> error_list;
int display_build; // 0: none, 1: normal (default), 2: version + hotfix only
int report_precision;
int report_pets_separately;
Expand Down Expand Up @@ -730,25 +730,44 @@ struct sim_t : private sc_thread_t
/**
* Create error with printf formatting.
*/
template <typename... Args>
void errorf( error_level_e level, util::string_view format, Args&&... args )
{
if ( thread_index != 0 )
return;

set_error( level, fmt::sprintf( format, std::forward<Args>(args)... ) );
}

template <typename... Args>
void errorf( util::string_view format, Args&&... args )
{
if ( thread_index != 0 )
return;

set_error( fmt::sprintf( format, std::forward<Args>(args)... ) );
set_error( error_level_e::TRIVIAL, fmt::sprintf( format, std::forward<Args>(args)... ) );
}


/**
* Create error using fmt libraries python-like formatting syntax.
*/
template <typename... Args>
void error( error_level_e level, fmt::format_string<Args...> format, Args&&... args )
{
if ( thread_index != 0 )
return;

set_error( level, fmt::vformat( format, fmt::make_format_args( args... ) ) );
}

template <typename... Args>
void error( fmt::format_string<Args...> format, Args&&... args )
{
if ( thread_index != 0 )
return;

set_error( fmt::vformat( format, fmt::make_format_args( args... ) ) );
set_error( error_level_e::TRIVIAL, fmt::vformat( format, fmt::make_format_args( args... ) ) );
}

void abort();
Expand Down Expand Up @@ -821,7 +840,7 @@ struct sim_t : private sc_thread_t
}

private:
void set_error(std::string error);
void set_error( error_level_e level, std::string error );
void do_pause();
void print_spell_query();
void enable_debug_seed();
Expand Down
15 changes: 15 additions & 0 deletions engine/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2767,6 +2767,21 @@ const char* util::trait_definition_op_string( trait_definition_op op )
return "unk";
}
}

const char* util::error_level_string( error_level_e level )
{
switch ( level )
{
case error_level_e::TRIVIAL: return "Trivial";
case error_level_e::MODERATE: return "Moderate";
case error_level_e::SEVERE: return "Severe";
case error_level_e::FIGHT_STYLE: return "Invalid Fight Style";
case error_level_e::TALENT_HASH: return "Invalid Talent String";
case error_level_e::WORK_IN_PROGRESS: return "Work-in-Progress";
default: return "Unknown";
}
}

/// Textual representation of rppm scaling bitfield
std::string util::rppm_scaling_string( unsigned s )
{
Expand Down
1 change: 1 addition & 0 deletions engine/util/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const char* action_energize_type_string( action_energize energize_type );
const char* action_type_string( action_e type );
const char* talent_tree_string( talent_tree type );
const char* trait_definition_op_string( trait_definition_op op );
const char* error_level_string( error_level_e level );

std::string rppm_scaling_string ( unsigned );
std::string profile_source_string( profile_source );
Expand Down
6 changes: 3 additions & 3 deletions qt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ void SC_MainWindow::deleteSim( std::shared_ptr<sim_t>& sim, SC_TextEdit* append_
if ( sim )
{
std::list<std::string> files;
std::vector<std::string> errorListCopy( sim->error_list );
std::vector<std::pair<error_level_e, std::string> errorListCopy( sim->error_list );
files.push_back( sim->output_file_str );
files.push_back( sim->html_file_str );
files.push_back( sim->json_file_str );
Expand Down Expand Up @@ -734,9 +734,9 @@ void SC_MainWindow::importFinished()
simulateTab->append_Text( QString( "# " ) + importThread->error );
}

for ( const std::string& error : import_sim->error_list )
for ( const auto& error : import_sim->error_list )
{
simulateTab->append_Text( QString( "# " ) + QString::fromStdString( error ) );
simulateTab->append_Text( QString( "# " ) + QString::fromStdString( error.second ) );
}
deleteSim( import_sim, simulateTab->current_Text() );
}
Expand Down
8 changes: 4 additions & 4 deletions qt/sc_SimulationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ void SC_SimulateThread::run()
else
{
error_category = tr( "Simulation runtime error" );
range::for_each( sim->error_list, [ this ]( const std::string& str ) {
range::for_each( sim->error_list, [ this ]( const auto& error ) {
if ( !error_str.isEmpty() )
{
error_str += "\n";
}

error_str += QString::fromStdString( str );
error_str += QString::fromStdString( error.second );
} );
}
}
Expand All @@ -104,13 +104,13 @@ void SC_SimulateThread::run()
error_category = tr( "Simulation runtime error" );
std::string error_str_;
print_exception( error_str_, e );
range::for_each( sim->error_list, [ this ]( const std::string& str ) {
range::for_each( sim->error_list, [ this ]( const auto& error ) {
if ( !error_str.isEmpty() )
{
error_str += "\n";
}

error_str += QString::fromStdString( str );
error_str += QString::fromStdString( error.second );
} );
error_str += QString::fromStdString( error_str_ );
}
Expand Down
Loading