refactor how error output is created and only print input and parsed line if they differ in text

This commit is contained in:
Axel Kohlmeyer
2025-01-17 18:06:31 -05:00
parent 9b443c9a4d
commit e350f28e26
5 changed files with 63 additions and 55 deletions

View File

@ -121,16 +121,9 @@ void Error::all(const std::string &file, int line, int failed, const std::string
std::string lastcmd = "(unknown)";
std::string mesg = "ERROR: " + str + fmt::format(" ({}:{})\n", truncpath(file), line);
if (input && input->line) lastcmd = input->line;
// add text about the input following the error message
if (failed > NOLASTLINE) {
try {
mesg += fmt::format("Last input line: {}\n", lastcmd);
if (failed > NOPOINTER) mesg += utils::point_to_error(input, failed);
} catch (fmt::format_error &) {
; // do nothing
}
}
if (failed > NOLASTLINE) mesg += utils::point_to_error(input, failed);
if (comm->me == 0) utils::logmesg(lmp,mesg);
// allow commands if an exception was caught in a run
@ -153,23 +146,11 @@ void Error::all(const std::string &file, int line, int failed, const std::string
void Error::one(const std::string &file, int line, int failed, const std::string &str)
{
int me;
std::string lastcmd = "(unknown)";
MPI_Comm_rank(world,&me);
if (input && input->line) lastcmd = input->line;
std::string mesg;
try {
if (failed == NOLASTLINE) {
mesg = fmt::format("ERROR on proc {}: {} ({}:{})\n", me, str, truncpath(file), line);
} else {
mesg = fmt::format("ERROR on proc {}: {} ({}:{})\nLast input line: {}\n",
me, str, truncpath(file), line, lastcmd);
}
if (failed > NOPOINTER) mesg += utils::point_to_error(input, failed);
} catch (fmt::format_error &) {
; // do nothing
}
std::string mesg = fmt::format("ERROR on proc {}: {} ({}:{})\n", comm->me, str,
truncpath(file), line);
if (failed > NOPOINTER) mesg += utils::point_to_error(input, failed);
utils::logmesg(lmp,mesg);
if (universe->nworlds > 1)