improve error messages

This commit is contained in:
Axel Kohlmeyer
2022-09-11 21:53:14 -04:00
parent c235cbee71
commit 34714dba29
4 changed files with 19 additions and 12 deletions

View File

@ -41,7 +41,7 @@ void WriteCoeff::command(int narg, char **arg)
if (domain->box_exist == 0) if (domain->box_exist == 0)
error->all(FLERR, "Write_coeff command before simulation box is defined"); error->all(FLERR, "Write_coeff command before simulation box is defined");
if (narg != 1) error->all(FLERR, "Illegal write_coeff command"); if (narg != 1) utils::missing_cmd_args(FLERR, "write_coeff", error);
char *file = utils::strdup(fmt::format("{}.tmp", arg[0])); char *file = utils::strdup(fmt::format("{}.tmp", arg[0]));
@ -167,6 +167,5 @@ void WriteCoeff::command(int narg, char **arg)
fclose(two); fclose(two);
platform::unlink(file); platform::unlink(file);
} }
delete[] file; delete[] file;
} }

View File

@ -57,7 +57,7 @@ void WriteData::command(int narg, char **arg)
if (domain->box_exist == 0) if (domain->box_exist == 0)
error->all(FLERR,"Write_data command before simulation box is defined"); error->all(FLERR,"Write_data command before simulation box is defined");
if (narg < 1) error->all(FLERR,"Illegal write_data command"); if (narg < 1) utils::missing_cmd_args(FLERR, "write_data", error);
// if filename contains a "*", replace with current timestep // if filename contains a "*", replace with current timestep
@ -79,10 +79,10 @@ void WriteData::command(int narg, char **arg)
int iarg = 1; int iarg = 1;
while (iarg < narg) { while (iarg < narg) {
if (strcmp(arg[iarg],"pair") == 0) { if (strcmp(arg[iarg],"pair") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal write_data command"); if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "write_data pair", error);
if (strcmp(arg[iarg+1],"ii") == 0) pairflag = II; if (strcmp(arg[iarg+1],"ii") == 0) pairflag = II;
else if (strcmp(arg[iarg+1],"ij") == 0) pairflag = IJ; else if (strcmp(arg[iarg+1],"ij") == 0) pairflag = IJ;
else error->all(FLERR,"Illegal write_data command"); else error->all(FLERR,"Unknown write_data pair option: {}", arg[iarg+1]);
iarg += 2; iarg += 2;
} else if (strcmp(arg[iarg],"noinit") == 0) { } else if (strcmp(arg[iarg],"noinit") == 0) {
noinit = 1; noinit = 1;
@ -97,12 +97,12 @@ void WriteData::command(int narg, char **arg)
lmapflag = 0; lmapflag = 0;
iarg++; iarg++;
} else if (strcmp(arg[iarg],"types") == 0) { } else if (strcmp(arg[iarg],"types") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal write_data command"); if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "write_data types", error);
if (strcmp(arg[iarg+1],"numeric") == 0) atom->types_style = Atom::NUMERIC; if (strcmp(arg[iarg+1],"numeric") == 0) atom->types_style = Atom::NUMERIC;
else if (strcmp(arg[iarg+1],"labels") == 0) atom->types_style = Atom::LABELS; else if (strcmp(arg[iarg+1],"labels") == 0) atom->types_style = Atom::LABELS;
else error->all(FLERR,"Illegal write_data command"); else error->all(FLERR,"Unknown write_data types option: {}", arg[iarg+1]);
iarg += 2; iarg += 2;
} else error->all(FLERR,"Illegal write_data command"); } else error->all(FLERR,"Unknown write_data keyword: {}", arg[iarg]);
} }
// init entire system since comm->exchange is done // init entire system since comm->exchange is done

View File

@ -33,7 +33,7 @@ using namespace LAMMPS_NS;
void WriteDump::command(int narg, char **arg) void WriteDump::command(int narg, char **arg)
{ {
if (narg < 3) error->all(FLERR, "Illegal write_dump command"); if (narg < 3) utils::missing_cmd_args(FLERR, "write_dump", error);
// modindex = index in args of "modify" keyword // modindex = index in args of "modify" keyword
// will be narg if "modify" is not present // will be narg if "modify" is not present

View File

@ -439,9 +439,17 @@ TEST_F(FileOperationsTest, write_data)
ASSERT_FILE_EXISTS("charge.data"); ASSERT_FILE_EXISTS("charge.data");
ASSERT_EQ(count_lines("charge.data"), 30); ASSERT_EQ(count_lines("charge.data"), 30);
TEST_FAILURE(".*ERROR: Illegal write_data command.*", command("write_data");); TEST_FAILURE(".*ERROR: Illegal write_data command: missing argument.*", command("write_data"););
TEST_FAILURE(".*ERROR: Illegal write_data command.*", command("write_data test.data xxxx");); TEST_FAILURE(".*ERROR: Unknown write_data keyword: xxxx.*",
TEST_FAILURE(".*ERROR: Illegal write_data command.*", command("write_data test.data pair xx");); command("write_data test.data xxxx"););
TEST_FAILURE(".*ERROR: Illegal write_data pair command: missing argument.*",
command("write_data test.data pair"););
TEST_FAILURE(".*ERROR: Unknown write_data pair option: xx.*",
command("write_data test.data pair xx"););
TEST_FAILURE(".*ERROR: Illegal write_data types command: missing argument.*",
command("write_data test.data types"););
TEST_FAILURE(".*ERROR: Unknown write_data types option: xx.*",
command("write_data test.data types xx"););
TEST_FAILURE(".*ERROR on proc 0: Cannot open data file some_crazy_dir/test.data:" TEST_FAILURE(".*ERROR on proc 0: Cannot open data file some_crazy_dir/test.data:"
" No such file or directory.*", " No such file or directory.*",
command("write_data some_crazy_dir/test.data");); command("write_data some_crazy_dir/test.data"););