avoid segfault on command errors in force style unit tests and print error mesage instead

This commit is contained in:
Axel Kohlmeyer
2023-11-16 15:53:23 -05:00
parent ac5f28719b
commit ddd5cc1a73
5 changed files with 87 additions and 11 deletions

View File

@ -26,6 +26,7 @@
#include "atom.h"
#include "compute.h"
#include "dihedral.h"
#include "exceptions.h"
#include "fmt/format.h"
#include "force.h"
#include "info.h"
@ -59,7 +60,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
delete lmp;
}
LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newton = true)
LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true)
{
LAMMPS *lmp = new LAMMPS(args, MPI_COMM_WORLD);
@ -88,7 +89,21 @@ LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newto
// utility lambdas to improve readability
auto command = [&](const std::string &line) {
lmp->input->one(line);
try {
lmp->input->one(line);
} catch (LAMMPSAbortException &ae) {
fprintf(stderr, "LAMMPS Error: %s\n", ae.what());
exit(2);
} catch (LAMMPSException &e) {
fprintf(stderr, "LAMMPS Error: %s\n", e.what());
exit(3);
} catch (fmt::format_error &fe) {
fprintf(stderr, "fmt::format_error: %s\n", fe.what());
exit(4);
} catch (std::exception &e) {
fprintf(stderr, "General exception: %s\n", e.what());
exit(5);
}
};
auto parse_input_script = [&](const std::string &filename) {
lmp->input->file(filename.c_str());