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

Improve error reporting #79381

Open
wants to merge 1 commit into
base: master
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
10 changes: 5 additions & 5 deletions src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ static void debug_error_prompt(

std::string formatted_report =
string_format( // developer-facing error report. INTENTIONALLY UNTRANSLATED!
" DEBUG : %s\n\n"
" FUNCTION : %s\n"
" FILE : %s\n"
" LINE : %s\n"
" VERSION : %s\n",
" DEBUG : %s\n\n"
" REPORTING FUNCTION : %s\n"
" C++ SOURCE FILE : %s\n"
" LINE : %s\n"
" VERSION : %s\n",
text, funcname, filename, line, getVersionString()
);

Expand Down
28 changes: 14 additions & 14 deletions src/flexbuffer_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,23 @@ std::string Json::str() const
bool JsonValue::read( bool &b, bool throw_on_error ) const
{
if( !test_bool() ) {
return error_or_false( throw_on_error, "Expected bool" );
return error_or_false( throw_on_error, "Syntax error. Expected bool" );
}
b = get_bool();
return true;
}
bool JsonValue::read( char &c, bool throw_on_error ) const
{
if( !test_number() ) {
return error_or_false( throw_on_error, "Expected number" );
return error_or_false( throw_on_error, "Syntax error. Expected number" );
}
c = get_int();
return true;
}
bool JsonValue::read( signed char &c, bool throw_on_error ) const
{
if( !test_number() ) {
return error_or_false( throw_on_error, "Expected number" );
return error_or_false( throw_on_error, "Syntax error. Expected number" );
}
// TODO: test for overflow
c = get_int();
Expand All @@ -168,7 +168,7 @@ bool JsonValue::read( signed char &c, bool throw_on_error ) const
bool JsonValue::read( unsigned char &c, bool throw_on_error ) const
{
if( !test_number() ) {
return error_or_false( throw_on_error, "Expected number" );
return error_or_false( throw_on_error, "Syntax error. Expected number" );
}
// TODO: test for overflow
c = get_int();
Expand All @@ -177,7 +177,7 @@ bool JsonValue::read( unsigned char &c, bool throw_on_error ) const
bool JsonValue::read( short unsigned int &s, bool throw_on_error ) const
{
if( !test_number() ) {
return error_or_false( throw_on_error, "Expected number" );
return error_or_false( throw_on_error, "Syntax error. Expected number" );
}
// TODO: test for overflow
s = get_int();
Expand All @@ -186,7 +186,7 @@ bool JsonValue::read( short unsigned int &s, bool throw_on_error ) const
bool JsonValue::read( short int &s, bool throw_on_error ) const
{
if( !test_number() ) {
return error_or_false( throw_on_error, "Expected number" );
return error_or_false( throw_on_error, "Syntax error. Expected number" );
}
// TODO: test for overflow
s = get_int();
Expand All @@ -195,55 +195,55 @@ bool JsonValue::read( short int &s, bool throw_on_error ) const
bool JsonValue::read( int &i, bool throw_on_error ) const
{
if( !test_number() ) {
return error_or_false( throw_on_error, "Expected number" );
return error_or_false( throw_on_error, "Syntax error. Expected number" );
}
i = get_int();
return true;
}
bool JsonValue::read( int64_t &i, bool throw_on_error ) const
{
if( !test_number() ) {
return error_or_false( throw_on_error, "Expected number" );
return error_or_false( throw_on_error, "Syntax error. Expected number" );
}
i = get_int64();
return true;
}
bool JsonValue::read( uint64_t &i, bool throw_on_error ) const
{
if( !test_number() ) {
return error_or_false( throw_on_error, "Expected number" );
return error_or_false( throw_on_error, "Syntax error. Expected number" );
}
i = get_uint64();
return true;
}
bool JsonValue::read( unsigned int &u, bool throw_on_error ) const
{
if( !test_number() ) {
return error_or_false( throw_on_error, "Expected number" );
return error_or_false( throw_on_error, "Syntax error. Expected number" );
}
u = get_uint();
return true;
}
bool JsonValue::read( float &f, bool throw_on_error ) const
{
if( !test_number() ) {
return error_or_false( throw_on_error, "Expected number" );
return error_or_false( throw_on_error, "Syntax error. Expected number" );
}
f = get_float();
return true;
}
bool JsonValue::read( double &d, bool throw_on_error ) const
{
if( !test_number() ) {
return error_or_false( throw_on_error, "Expected number" );
return error_or_false( throw_on_error, "Syntax error. Expected number" );
}
d = get_float();
return true;
}
bool JsonValue::read( std::string &s, bool throw_on_error ) const
{
if( !test_string() ) {
return error_or_false( throw_on_error, "Expected string" );
return error_or_false( throw_on_error, "Syntax error. Expected string" );
}
s = get_string();
return true;
Expand Down Expand Up @@ -340,7 +340,7 @@ void JsonObject::error_skipped_members( const std::vector<size_t> &skipped_membe
"\"//~\" should be within a text object and contain comments for translators." );
} else {
jo.throw_error_at( name.c_str(),
string_format( "Invalid or misplaced field name \"%s\" in JSON data",
string_format( "Unread data. Invalid or misplaced field name \"%s\" in JSON data",
name.c_str() ) );
}
} catch( const JsonError &e ) {
Expand Down
12 changes: 8 additions & 4 deletions src/generic_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,11 @@ inline void mandatory( const JsonObject &jo, const bool was_loaded, const std::s
if( !jo.read( name, member ) ) {
if( !was_loaded ) {
if( jo.has_member( name ) ) {
jo.throw_error( str_cat( "failed to read mandatory member \"", name, "\"" ) );
jo.throw_error( str_cat( "object beginning at this line failed to read mandatory member \"", name,
"\"" ) );
} else {
jo.throw_error( str_cat( "missing mandatory member \"", name, "\"" ) );
jo.throw_error( str_cat( "object beginning at this line missing mandatory member \"", name,
"\"" ) );
}
}
}
Expand All @@ -579,9 +581,11 @@ inline void mandatory( const JsonObject &jo, const bool was_loaded, const std::s
if( !reader( jo, name, member, was_loaded ) ) {
if( !was_loaded ) {
if( jo.has_member( name ) ) {
jo.throw_error( str_cat( "failed to read mandatory member \"", name, "\"" ) );
jo.throw_error( str_cat( "object beginning at this line failed to read mandatory member \"", name,
"\"" ) );
} else {
jo.throw_error( str_cat( "missing mandatory member \"", name, "\"" ) );
jo.throw_error( str_cat( "object beginning at this line missing mandatory member \"", name,
"\"" ) );
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,7 @@ std::string TextJsonIn::line_number( int offset_modifier )
std::stringstream ret;
switch( error_log_format ) {
case error_log_format_t::human_readable:
ret << name << ":" << line << ":" << offset;
ret << "file " << name << ", at line " << line << ", character " << offset;
break;
case error_log_format_t::github_action:
ret.imbue( std::locale::classic() );
Expand Down Expand Up @@ -2012,7 +2012,7 @@ void TextJsonIn::error( int offset, const std::string &message )
std::ostringstream err_header;
switch( error_log_format ) {
case error_log_format_t::human_readable:
err_header << "Json error: " << line_number( offset ) << ": ";
err_header << "Json error: " << line_number( offset ) << ":\n";
break;
case error_log_format_t::github_action:
err_header << "::error " << line_number( offset ) << "::";
Expand Down
Loading