add overloads for Error::all() and Error::one() that can point out the location of a faulty argument

This commit is contained in:
Axel Kohlmeyer
2025-01-15 23:10:50 -05:00
parent 48f49837d8
commit 8c93986e47
6 changed files with 96 additions and 24 deletions

View File

@ -132,6 +132,28 @@ void utils::missing_cmd_args(const std::string &file, int line, const std::strin
if (error) error->all(file, line, "Illegal {} command: missing argument(s)", cmd);
}
std::string utils::point_to_error(Input *input, int failedarg)
{
if (input) {
std::string cmdline = "Preprocessed: ";
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) {
if (i == failedarg) indicator = cmdline.size();
cmdline += input->arg[i];
cmdline += ' ';
}
// construct and append error indicator line
cmdline += '\n';
cmdline += std::string(indicator, ' ');
cmdline += "^\n";
return cmdline;
} else return std::string("(Failed command line text not available)");
}
/* specialization for the case of just a single string argument */
void utils::logmesg(LAMMPS *lmp, const std::string &mesg)