add method that allows suppressing printing error messages immediately
This commit is contained in:
@ -35,7 +35,7 @@ static std::string truncpath(const std::string &path)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
Error::Error(LAMMPS *lmp)
|
||||
: Pointers(lmp), numwarn(0), maxwarn(100), allwarn(0)
|
||||
: Pointers(lmp), numwarn(0), maxwarn(100), allwarn(0), showerror(1)
|
||||
{
|
||||
last_error_message.clear();
|
||||
last_error_type = ERROR_NONE;
|
||||
@ -56,7 +56,7 @@ void Error::universe_all(const std::string &file, int line, const std::string &s
|
||||
} catch (fmt::format_error &) {
|
||||
; // do nothing
|
||||
}
|
||||
if (universe->me == 0) {
|
||||
if (showerror && (universe->me == 0)) {
|
||||
if (universe->uscreen) fputs(mesg.c_str(),universe->uscreen);
|
||||
if (universe->ulogfile) fputs(mesg.c_str(),universe->ulogfile);
|
||||
}
|
||||
@ -84,7 +84,10 @@ void Error::universe_one(const std::string &file, int line, const std::string &s
|
||||
{
|
||||
std::string mesg = fmt::format("ERROR on proc {}: {} ({}:{})\n",
|
||||
universe->me,str,truncpath(file),line);
|
||||
if (universe->uscreen) fputs(mesg.c_str(),universe->uscreen);
|
||||
if (showerror) {
|
||||
if (universe->uscreen) fputs(mesg.c_str(),universe->uscreen);
|
||||
if (universe->ulogfile) fputs(mesg.c_str(),universe->ulogfile);
|
||||
}
|
||||
utils::flush_buffers(lmp);
|
||||
|
||||
// allow commands if an exception was caught in a run
|
||||
@ -131,7 +134,7 @@ void Error::all(const std::string &file, int line, int failed, const std::string
|
||||
|
||||
if (failed > NOLASTLINE) mesg += utils::point_to_error(input, failed);
|
||||
if (failed == ARGZERO) mesg += utils::point_to_error(input, 0);
|
||||
if (me == 0) utils::logmesg(lmp,mesg);
|
||||
if (showerror && (me == 0)) utils::logmesg(lmp,mesg);
|
||||
utils::flush_buffers(lmp);
|
||||
|
||||
// allow commands if an exception was caught in a run
|
||||
@ -164,11 +167,12 @@ void Error::one(const std::string &file, int line, int failed, const std::string
|
||||
std::string mesg = fmt::format("ERROR on proc {}: {} ({}:{})\n", me, str, truncpath(file), line);
|
||||
if (failed > NOPOINTER) mesg += utils::point_to_error(input, failed);
|
||||
if (failed == ARGZERO) mesg += utils::point_to_error(input, 0);
|
||||
utils::logmesg(lmp,mesg);
|
||||
if (showerror) utils::logmesg(lmp,mesg);
|
||||
|
||||
if (universe->nworlds > 1)
|
||||
if (universe->uscreen)
|
||||
fputs(mesg.c_str(),universe->uscreen);
|
||||
if (showerror && (universe->nworlds > 1)) {
|
||||
if (universe->uscreen) fputs(mesg.c_str(),universe->uscreen);
|
||||
if (universe->ulogfile) fputs(mesg.c_str(),universe->ulogfile);
|
||||
}
|
||||
|
||||
utils::flush_buffers(lmp);
|
||||
// allow commands if an exception was caught in a run
|
||||
@ -213,8 +217,7 @@ void Error::warning(const std::string &file, int line, const std::string &str)
|
||||
{
|
||||
++numwarn;
|
||||
if ((maxwarn != 0) && ((numwarn > maxwarn) || (allwarn > maxwarn) || (maxwarn < 0))) return;
|
||||
std::string mesg = fmt::format("WARNING: {} ({}:{})\n",
|
||||
str,truncpath(file),line);
|
||||
std::string mesg = fmt::format("WARNING: {} ({}:{})\n", str,truncpath(file),line);
|
||||
if (screen) fputs(mesg.c_str(),screen);
|
||||
if (logfile) fputs(mesg.c_str(),logfile);
|
||||
}
|
||||
@ -308,3 +311,13 @@ void Error::set_last_error(const char *msg, ErrorType type)
|
||||
last_error_message = msg;
|
||||
last_error_type = type;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
enable or disable printing error messages. for use with library interface.
|
||||
if flag = 0 only last error message and type are updated.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Error::set_show_error(const int flag)
|
||||
{
|
||||
showerror = flag;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user