avoid segfault on command line errors

This commit is contained in:
Axel Kohlmeyer
2025-01-26 21:45:12 -05:00
parent 563b5b0997
commit 6bb022853e
2 changed files with 13 additions and 4 deletions

View File

@ -119,13 +119,18 @@ void Error::all(const std::string &file, int line, int failed, const std::string
{
MPI_Barrier(world);
// must get rank from communicator since "comm" instance may not yet exist
int me = 0;
MPI_Comm_rank(world, &me);
std::string lastcmd = "(unknown)";
std::string mesg = "ERROR: " + str + fmt::format(" ({}:{})\n", truncpath(file), line);
// add text about the input following the error message
if (failed > NOLASTLINE) mesg += utils::point_to_error(input, failed);
if (comm->me == 0) utils::logmesg(lmp,mesg);
if (me == 0) utils::logmesg(lmp,mesg);
utils::flush_buffers(lmp);
// allow commands if an exception was caught in a run
@ -150,8 +155,12 @@ void Error::one(const std::string &file, int line, int failed, const std::string
{
std::string lastcmd = "(unknown)";
std::string mesg = fmt::format("ERROR on proc {}: {} ({}:{})\n", comm->me, str,
truncpath(file), line);
// must get rank from communicator since "comm" instance may not yet exist
int me = 0;
MPI_Comm_rank(world, &me);
std::string mesg = fmt::format("ERROR on proc {}: {} ({}:{})\n", me, str, truncpath(file), line);
if (failed > NOPOINTER) mesg += utils::point_to_error(input, failed);
utils::logmesg(lmp,mesg);