diff --git a/src/error.cpp b/src/error.cpp index 1d656c1c45..d03e5453e9 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -118,36 +118,30 @@ void Error::all(const std::string &file, int line, int failed, const std::string { MPI_Barrier(world); - int me; std::string lastcmd = "(unknown)"; + std::string mesg = "ERROR: " + str + fmt::format(" ({}:{})\n", truncpath(file), line); - MPI_Comm_rank(world,&me); + if (input && input->line) lastcmd = input->line; - if (me == 0) { - std::string mesg = "ERROR: " + str; - - if (input && input->line) lastcmd = input->line; + if (failed > NOLASTLINE) { try { - mesg += fmt::format(" ({}:{})\nLast command: {}\n", truncpath(file),line,lastcmd); + mesg += fmt::format("Last input line: {}\n", lastcmd); if (failed > NOPOINTER) mesg += utils::point_to_error(input, failed); } catch (fmt::format_error &) { ; // do nothing } - utils::logmesg(lmp,mesg); } + if (comm->me == 0) utils::logmesg(lmp,mesg); // allow commands if an exception was caught in a run // update may be a null pointer when catching command-line errors if (update) update->whichflag = 0; - std::string msg = fmt::format("ERROR: {} ({}:{})\n", str, truncpath(file), line); - if (failed > NOPOINTER) msg += utils::point_to_error(input, failed); - if (universe->nworlds > 1) - throw LAMMPSAbortException(msg, universe->uworld); + throw LAMMPSAbortException(mesg, universe->uworld); else - throw LAMMPSException(msg); + throw LAMMPSException(mesg); } /* ---------------------------------------------------------------------- @@ -166,8 +160,12 @@ void Error::one(const std::string &file, int line, int failed, const std::string if (input && input->line) lastcmd = input->line; std::string mesg; try { - mesg = fmt::format("ERROR on proc {}: {} ({}:{})\nLast command: {}\n", - me,str,truncpath(file),line,lastcmd); + 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 diff --git a/src/error.h b/src/error.h index cf066338a4..0c446667e0 100644 --- a/src/error.h +++ b/src/error.h @@ -28,6 +28,7 @@ class Error : protected Pointers { void universe_warn(const std::string &, int, const std::string &); static constexpr int NOPOINTER = -2; + static constexpr int NOLASTLINE = -3; // regular error calls diff --git a/src/fix_print.cpp b/src/fix_print.cpp index ccef03c3ae..8e0a4a1921 100644 --- a/src/fix_print.cpp +++ b/src/fix_print.cpp @@ -38,7 +38,7 @@ FixPrint::FixPrint(LAMMPS *lmp, int narg, char **arg) : nevery = 1; } else { nevery = utils::inumeric(FLERR, arg[3], false, lmp); - if (nevery <= 0) error->all(FLERR, "Illegal fix print nevery value {}; must be > 0", nevery); + if (nevery <= 0) error->all(FLERR, 3, "Illegal fix print nevery value {}; must be > 0", nevery); } text = utils::strdup(arg[4]); @@ -121,12 +121,15 @@ void FixPrint::init() if (var_print) { ivar_print = input->variable->find(var_print); if (ivar_print < 0) - error->all(FLERR, "Variable {} for fix print timestep does not exist", var_print); + error->all(FLERR, Error::NOLASTLINE, "Variable {} for fix print timestep does not exist", + var_print); if (!input->variable->equalstyle(ivar_print)) - error->all(FLERR, "Variable {} for fix print timestep is invalid style", var_print); + error->all(FLERR, Error::NOLASTLINE, "Variable {} for fix print timestep is invalid style", + var_print); next_print = static_cast(input->variable->compute_equal(ivar_print)); if (next_print <= update->ntimestep) - error->all(FLERR, "Fix print timestep variable {} returned a bad timestep: {}", var_print, + error->all(FLERR, Error::NOLASTLINE, + "Fix print timestep variable {} returned a bad timestep: {}", var_print, next_print); } else { if (update->ntimestep % nevery) diff --git a/src/utils.cpp b/src/utils.cpp index bdb11ec9ab..4cb87d0131 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -135,15 +135,28 @@ void utils::missing_cmd_args(const std::string &file, int line, const std::strin std::string utils::point_to_error(Input *input, int failed) { if (input) { - std::string cmdline = "Preprocessed: "; + std::string cmdline = "--> parsed line: "; int indicator = cmdline.size(); // error indicator points to command by default cmdline += input->command; cmdline += ' '; // assemble pre-processed command line and update error indicator position, if needed. for (int i = 0; i < input->narg; ++i) { + std::string inputarg = input->arg[i]; if (i == failed) indicator = cmdline.size(); - cmdline += input->arg[i]; + + // argument contains whitespace. add quotes. check which type of quotes, too + if (inputarg.find_first_of(" \t\n") != std::string::npos) { + if (inputarg.find_first_of('"') != std::string::npos) { + cmdline += "'"; + cmdline += inputarg; + cmdline += "'"; + } else { + cmdline += '"'; + cmdline += inputarg; + cmdline += '"'; + } + } else cmdline += inputarg; cmdline += ' '; } // construct and append error indicator line diff --git a/src/variable.cpp b/src/variable.cpp index 031709166b..d20a134d0d 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -5227,14 +5227,14 @@ void Variable::print_var_error(const std::string &srcfile, const int lineno, if ((ivar >= 0) && (ivar < nvar)) { std::string msg = fmt::format("Variable {}: ",names[ivar]) + errmsg; if (global) - error->all(srcfile,lineno,msg); + error->all(srcfile, lineno, Error::NOLASTLINE, msg); else - error->one(srcfile,lineno,msg); + error->one(srcfile, lineno, Error::NOLASTLINE, msg); } else { if (global) - error->all(srcfile,lineno,errmsg); + error->all(srcfile,lineno, Error::NOLASTLINE, errmsg); else - error->one(srcfile,lineno,errmsg); + error->one(srcfile,lineno, Error::NOLASTLINE, errmsg); } }