avoid segfault on command errors in force style unit tests and print error mesage instead
This commit is contained in:
@ -26,6 +26,7 @@
|
|||||||
#include "angle.h"
|
#include "angle.h"
|
||||||
#include "atom.h"
|
#include "atom.h"
|
||||||
#include "compute.h"
|
#include "compute.h"
|
||||||
|
#include "exceptions.h"
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
#include "force.h"
|
#include "force.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
@ -90,7 +91,21 @@ LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newto
|
|||||||
|
|
||||||
// utility lambdas to improve readability
|
// utility lambdas to improve readability
|
||||||
auto command = [&](const std::string &line) {
|
auto command = [&](const std::string &line) {
|
||||||
|
try {
|
||||||
lmp->input->one(line);
|
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) {
|
auto parse_input_script = [&](const std::string &filename) {
|
||||||
lmp->input->file(filename.c_str());
|
lmp->input->file(filename.c_str());
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
#include "atom.h"
|
#include "atom.h"
|
||||||
#include "bond.h"
|
#include "bond.h"
|
||||||
#include "compute.h"
|
#include "compute.h"
|
||||||
|
#include "exceptions.h"
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
#include "force.h"
|
#include "force.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
@ -90,7 +91,21 @@ LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newto
|
|||||||
|
|
||||||
// utility lambdas to improve readability
|
// utility lambdas to improve readability
|
||||||
auto command = [&](const std::string &line) {
|
auto command = [&](const std::string &line) {
|
||||||
|
try {
|
||||||
lmp->input->one(line);
|
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) {
|
auto parse_input_script = [&](const std::string &filename) {
|
||||||
lmp->input->file(filename.c_str());
|
lmp->input->file(filename.c_str());
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
#include "atom.h"
|
#include "atom.h"
|
||||||
#include "compute.h"
|
#include "compute.h"
|
||||||
#include "dihedral.h"
|
#include "dihedral.h"
|
||||||
|
#include "exceptions.h"
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
#include "force.h"
|
#include "force.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
@ -88,7 +89,21 @@ LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newto
|
|||||||
|
|
||||||
// utility lambdas to improve readability
|
// utility lambdas to improve readability
|
||||||
auto command = [&](const std::string &line) {
|
auto command = [&](const std::string &line) {
|
||||||
|
try {
|
||||||
lmp->input->one(line);
|
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) {
|
auto parse_input_script = [&](const std::string &filename) {
|
||||||
lmp->input->file(filename.c_str());
|
lmp->input->file(filename.c_str());
|
||||||
|
|||||||
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "atom.h"
|
#include "atom.h"
|
||||||
#include "compute.h"
|
#include "compute.h"
|
||||||
|
#include "exceptions.h"
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
#include "force.h"
|
#include "force.h"
|
||||||
#include "improper.h"
|
#include "improper.h"
|
||||||
@ -90,7 +91,21 @@ LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newto
|
|||||||
|
|
||||||
// utility lambdas to improve readability
|
// utility lambdas to improve readability
|
||||||
auto command = [&](const std::string &line) {
|
auto command = [&](const std::string &line) {
|
||||||
|
try {
|
||||||
lmp->input->one(line);
|
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) {
|
auto parse_input_script = [&](const std::string &filename) {
|
||||||
lmp->input->file(filename.c_str());
|
lmp->input->file(filename.c_str());
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
#include "atom.h"
|
#include "atom.h"
|
||||||
#include "compute.h"
|
#include "compute.h"
|
||||||
#include "domain.h"
|
#include "domain.h"
|
||||||
|
#include "exceptions.h"
|
||||||
#include "force.h"
|
#include "force.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
@ -92,8 +93,23 @@ LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newto
|
|||||||
|
|
||||||
// utility lambdas to improve readability
|
// utility lambdas to improve readability
|
||||||
auto command = [&](const std::string &line) {
|
auto command = [&](const std::string &line) {
|
||||||
|
try {
|
||||||
lmp->input->one(line);
|
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) {
|
auto parse_input_script = [&](const std::string &filename) {
|
||||||
lmp->input->file(filename.c_str());
|
lmp->input->file(filename.c_str());
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user