Skip to content

Commit

Permalink
validator: Conform to the new parser and preprocessor output style
Browse files Browse the repository at this point in the history
Because I overlooked the validator's dependency on the preprocessor
lineno_string() function, we wound up with badly-formatted output like
the following:

> 20140619 03:16:32 error validation:
> gui/default/widget/slider_minimal.cfg:53
>     included from gui/default.cfg:30
>     included from gui/default/widget/slider_minimal.cfg:100
>     included from gui/default.cfg:30: tag [wrong_tag] may not be used in [resolution]

This commit changes the validator's error formatting functions to
produce output more akin to the parser/preprocessor under the new
scheme introduced in version 1.11.10:

> 20140619 03:17:36 error validation: Tag [wrong_tag] may not be used in [resolution]
> at gui/default/widget/slider_minimal.cfg:53
>     included from gui/default.cfg:30
>     included from gui/default/widget/slider_minimal.cfg:100
>     included from gui/default.cfg:30

There are no translatable strings involved in this change, so this
commit may be safely backported to 1.12.
  • Loading branch information
irydacea committed Jun 19, 2014
1 parent 8a30f34 commit eed4ae8
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/serialization/schema_validator.cpp
Expand Up @@ -34,7 +34,7 @@ static lg::log_domain log_validation("validation");
static std::string at(const std::string & file, int line){
std::ostringstream ss;
ss << line << " " << file;
return ::lineno_string(ss.str());
return "at " + ::lineno_string(ss.str());
}

static void print_output(const std::string & message,bool flag_exception = false ){
Expand All @@ -55,53 +55,59 @@ static void extra_tag_error(const std::string & file, int line,
const std::string & name,int n,
const std::string & parent, bool flag_exception){
std::ostringstream ss;
ss <<at(file,line) << ": extra tag [" << name << "]; there may only be "
<< n << " ["<< name <<"] in [" << parent <<"]\n";
ss << "Extra tag [" << name << "]; there may only be "
<< n << " [" << name << "] in [" << parent << "]\n"
<< at(file, line) << "\n";
print_output (ss.str (),flag_exception);
}

static void wrong_tag_error(const std::string & file, int line,
const std::string & name,const std::string & parent,
bool flag_exception){
std::ostringstream ss;
ss <<at(file,line) << ": tag [" << name << "] may not be used in [" <<
parent <<"]\n";
ss << "Tag [" << name << "] may not be used in ["
<< parent << "]\n"
<< at(file, line) << "\n";
print_output (ss.str (),flag_exception);
}

static void missing_tag_error(const std::string & file, int line,
const std::string & name,int n,
const std::string & parent, bool flag_exception){
std::ostringstream ss;
ss <<at(file,line) << ": missing tag [" << name << "]; there must be "
<< n << " ["<< name <<"]s in [" << parent <<"]\n";
ss << "Missing tag [" << name << "]; there must be "
<< n << " [" << name << "]s in [" << parent << "]\n"
<< at(file, line) << "\n";
print_output (ss.str (),flag_exception);
}

static void extra_key_error(const std::string & file, int line,
const std::string & tag,const std::string & key,
bool flag_exception){
std::ostringstream ss;
ss << at(file,line) << ": Invalid key '"<< key <<"=' in tag ["<< tag
<< "] on line " << line << "\n";
ss << "Invalid key '" << key << "=' in tag [" << tag
<< "] on line " << line << "\n"
<< at(file, line) << "\n";
print_output (ss.str (),flag_exception);
}

static void missing_key_error(const std::string & file, int line,
const std::string & tag,const std::string & key,
bool flag_exception){
std::ostringstream ss;
ss << at(file,line) << ": In tag "<< tag
<< " which begins here, " << " missing key "<< key << "\n";
ss << "In tag " << tag
<< " which begins here, " << " missing key " << key << "\n"
<< at(file, line) << "\n";
print_output (ss.str (),flag_exception);
}

static void wrong_value_error(const std::string & file, int line,
const std::string & tag,const std::string & key,
const std::string & value,bool flag_exception){
std::ostringstream ss;
ss << at(file,line) << ": Invalid value '"<< value << "' in key '" << key <<
"=' in tag ["<< tag <<"] on line " << line << "'\n";
ss << "Invalid value '" << value << "' in key '" << key
<< "=' in tag [" << tag << "] on line " << line << "'\n"
<< at(file, line) << "\n";
print_output (ss.str (),flag_exception);
}

Expand Down

0 comments on commit eed4ae8

Please sign in to comment.