diff --git a/src/write_coeff.cpp b/src/write_coeff.cpp index f71cab0fdd..9dfdeb5141 100644 --- a/src/write_coeff.cpp +++ b/src/write_coeff.cpp @@ -41,7 +41,7 @@ void WriteCoeff::command(int narg, char **arg) if (domain->box_exist == 0) 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])); @@ -167,6 +167,5 @@ void WriteCoeff::command(int narg, char **arg) fclose(two); platform::unlink(file); } - delete[] file; } diff --git a/src/write_data.cpp b/src/write_data.cpp index 447399c65f..75182c869f 100644 --- a/src/write_data.cpp +++ b/src/write_data.cpp @@ -57,7 +57,7 @@ void WriteData::command(int narg, char **arg) if (domain->box_exist == 0) 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 @@ -79,10 +79,10 @@ void WriteData::command(int narg, char **arg) int iarg = 1; while (iarg < narg) { 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; 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; } else if (strcmp(arg[iarg],"noinit") == 0) { noinit = 1; @@ -97,12 +97,12 @@ void WriteData::command(int narg, char **arg) lmapflag = 0; iarg++; } 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; 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; - } 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 diff --git a/src/write_dump.cpp b/src/write_dump.cpp index e1a3a6b74d..a7f143aa43 100644 --- a/src/write_dump.cpp +++ b/src/write_dump.cpp @@ -33,7 +33,7 @@ using namespace LAMMPS_NS; 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 // will be narg if "modify" is not present diff --git a/unittest/formats/test_file_operations.cpp b/unittest/formats/test_file_operations.cpp index d0a6ef873c..ef954b51f3 100644 --- a/unittest/formats/test_file_operations.cpp +++ b/unittest/formats/test_file_operations.cpp @@ -439,9 +439,17 @@ TEST_F(FileOperationsTest, write_data) ASSERT_FILE_EXISTS("charge.data"); ASSERT_EQ(count_lines("charge.data"), 30); - TEST_FAILURE(".*ERROR: Illegal write_data command.*", command("write_data");); - TEST_FAILURE(".*ERROR: Illegal write_data command.*", command("write_data test.data xxxx");); - TEST_FAILURE(".*ERROR: Illegal write_data command.*", command("write_data test.data pair xx");); + TEST_FAILURE(".*ERROR: Illegal write_data command: missing argument.*", command("write_data");); + TEST_FAILURE(".*ERROR: Unknown write_data keyword: xxxx.*", + 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:" " No such file or directory.*", command("write_data some_crazy_dir/test.data"););