From 9beb60c71370182fb6004a7019c550fd919498d3 Mon Sep 17 00:00:00 2001 From: Jiancheng Chen <2742581175@qq.com> Date: Thu, 18 Aug 2022 11:22:36 +0800 Subject: [PATCH 1/8] improve error messages in change_box,create_box,domain,input,lattice and neighbor.cpp --- src/change_box.cpp | 35 ++++++++++++++--------------- src/create_box.cpp | 22 +++++++++--------- src/domain.cpp | 6 ++--- src/input.cpp | 8 +++---- src/lattice.cpp | 56 +++++++++++++++++++++++++--------------------- src/neighbor.cpp | 6 ++--- 6 files changed, 69 insertions(+), 64 deletions(-) diff --git a/src/change_box.cpp b/src/change_box.cpp index 08af5f11c9..b26d7803ed 100644 --- a/src/change_box.cpp +++ b/src/change_box.cpp @@ -46,14 +46,14 @@ void ChangeBox::command(int narg, char **arg) if (domain->box_exist == 0) error->all(FLERR,"Change_box command before simulation box is defined"); - if (narg < 2) error->all(FLERR,"Illegal change_box command"); + if (narg < 2) utils::missing_cmd_args(FLERR, "change_box", error); if (comm->me == 0) utils::logmesg(lmp,"Changing box ...\n"); // group int igroup = group->find(arg[0]); - if (igroup == -1) error->all(FLERR,"Could not find change_box group ID"); + if (igroup == -1) error->all(FLERR,"Could not find change_box group ID {}", arg[0]); int groupbit = group->bitmask[igroup]; // parse operation arguments @@ -70,7 +70,7 @@ void ChangeBox::command(int narg, char **arg) while (iarg < narg) { if (strcmp(arg[iarg],"x") == 0 || strcmp(arg[iarg],"y") == 0 || strcmp(arg[iarg],"z") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal change_box command"); + if (iarg+2 > narg) error->all(FLERR, "Illegal change_box {} command: missing argument(s)", arg[iarg]); ops[nops].style = XYZ; if (strcmp(arg[iarg],"x") == 0) ops[nops].dim = X; else if (strcmp(arg[iarg],"y") == 0) ops[nops].dim = Y; @@ -80,7 +80,7 @@ void ChangeBox::command(int narg, char **arg) error->all(FLERR,"Cannot change_box in z dimension for 2d simulation"); if (strcmp(arg[iarg+1],"final") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal change_box command"); + if (iarg+4 > narg) error->all(FLERR, "Illegal change_box {} final command: missing argument(s)", arg[iarg]); ops[nops].flavor = FINAL; ops[nops].flo = utils::numeric(FLERR,arg[iarg+2],false,lmp); ops[nops].fhi = utils::numeric(FLERR,arg[iarg+3],false,lmp); @@ -88,7 +88,7 @@ void ChangeBox::command(int narg, char **arg) nops++; iarg += 4; } else if (strcmp(arg[iarg+1],"delta") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal change_box command"); + if (iarg+4 > narg) error->all(FLERR, "Illegal change_box {} delta command: missing argument(s)", arg[iarg]); ops[nops].flavor = DELTA; ops[nops].dlo = utils::numeric(FLERR,arg[iarg+2],false,lmp); ops[nops].dhi = utils::numeric(FLERR,arg[iarg+3],false,lmp); @@ -96,7 +96,7 @@ void ChangeBox::command(int narg, char **arg) nops++; iarg += 4; } else if (strcmp(arg[iarg+1],"scale") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal change_box command"); + if (iarg+3 > narg) error->all(FLERR, "Illegal change_box {} scale command: missing argument(s)", arg[iarg]); ops[nops].flavor = SCALE; ops[nops].scale = utils::numeric(FLERR,arg[iarg+2],false,lmp); ops[nops].vdim1 = ops[nops].vdim2 = -1; @@ -112,11 +112,11 @@ void ChangeBox::command(int narg, char **arg) else ops[nops-1].vdim1 = ops[nops].dim; iarg += 2; - } else error->all(FLERR,"Illegal change_box command"); + } else error->all(FLERR, "Unknown change_box {} argument: {}", arg[iarg], arg[iarg+1]); } else if (strcmp(arg[iarg],"xy") == 0 || strcmp(arg[iarg],"xz") == 0 || strcmp(arg[iarg],"yz") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal change_box command"); + if (iarg+2 > narg) error->all(FLERR, "Illegal change_box {} command: missing argument(s)", arg[iarg]); ops[nops].style = TILT; if (strcmp(arg[iarg],"xy") == 0) ops[nops].dim = XY; else if (strcmp(arg[iarg],"xz") == 0) ops[nops].dim = XZ; @@ -126,21 +126,21 @@ void ChangeBox::command(int narg, char **arg) error->all(FLERR,"Cannot change_box in xz or yz for 2d simulation"); if (strcmp(arg[iarg+1],"final") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal change_box command"); + if (iarg+3 > narg) error->all(FLERR, "Illegal change_box {} final command: missing argument(s)", arg[iarg]); ops[nops].flavor = FINAL; ops[nops].ftilt = utils::numeric(FLERR,arg[iarg+2],false,lmp); nops++; iarg += 3; } else if (strcmp(arg[iarg+1],"delta") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal change_box command"); + if (iarg+3 > narg) error->all(FLERR, "Illegal change_box {} delta command: missing argument(s)", arg[iarg]); ops[nops].flavor = DELTA; ops[nops].dtilt = utils::numeric(FLERR,arg[iarg+2],false,lmp); nops++; iarg += 3; - } else error->all(FLERR,"Illegal change_box command"); + } else error->all(FLERR, "Unknown change_box {} argument: {}", arg[iarg], arg[iarg+1]); } else if (strcmp(arg[iarg],"boundary") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal change_box command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "change_box boundary", error); ops[nops].style = BOUNDARY; ops[nops].boundindex = iarg+1; nops++; @@ -157,7 +157,6 @@ void ChangeBox::command(int narg, char **arg) iarg += 1; } else if (strcmp(arg[iarg],"set") == 0) { - if (iarg+1 > narg) error->all(FLERR,"Illegal change_box command"); ops[nops].style = SET; nops++; iarg += 1; @@ -170,7 +169,7 @@ void ChangeBox::command(int narg, char **arg) } else break; } - if (nops == 0) error->all(FLERR,"Illegal change_box command"); + if (nops == 0) error->all(FLERR, "Unknown change_box keyword: {}", arg[iarg]); // move_atoms = 1 if need to move atoms to new procs after box changes // anything other than ORTHO or TRICLINIC may cause atom movement @@ -393,19 +392,19 @@ void ChangeBox::command(int narg, char **arg) void ChangeBox::options(int narg, char **arg) { - if (narg < 0) error->all(FLERR,"Illegal change_box command"); + if (narg < 0) utils::missing_cmd_args(FLERR, "change_box", error); scaleflag = 1; int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg],"units") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal change_box command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "change_box units", error); if (strcmp(arg[iarg+1],"box") == 0) scaleflag = 0; else if (strcmp(arg[iarg+1],"lattice") == 0) scaleflag = 1; - else error->all(FLERR,"Illegal change_box command"); + else error->all(FLERR, "Invalid change_box units argument: {}", arg[iarg+1]); iarg += 2; - } else error->all(FLERR,"Illegal change_box command"); + } else error->all(FLERR,"Unknown change_box keyword: {}", arg[iarg]); } } diff --git a/src/create_box.cpp b/src/create_box.cpp index cd6a63ca44..b05bfe0825 100644 --- a/src/create_box.cpp +++ b/src/create_box.cpp @@ -35,7 +35,7 @@ CreateBox::CreateBox(LAMMPS *lmp) : Command(lmp) {} void CreateBox::command(int narg, char **arg) { - if (narg < 2) error->all(FLERR, "Illegal create_box command"); + if (narg < 2) utils::missing_cmd_args(FLERR, "create_box", error); if (domain->box_exist) error->all(FLERR, "Cannot create_box after simulation box is defined"); if (domain->dimension == 2 && domain->zperiodic == 0) @@ -107,56 +107,56 @@ void CreateBox::command(int narg, char **arg) int iarg = 2; while (iarg < narg) { if (strcmp(arg[iarg], "bond/types") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "create_box bond/type", error); if (!atom->avec->bonds_allow) error->all(FLERR, "No bonds allowed with this atom style"); atom->nbondtypes = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "angle/types") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "create_box angle/types", error); if (!atom->avec->angles_allow) error->all(FLERR, "No angles allowed with this atom style"); atom->nangletypes = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "dihedral/types") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "create_box dihedral/types", error); if (!atom->avec->dihedrals_allow) error->all(FLERR, "No dihedrals allowed with this atom style"); atom->ndihedraltypes = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "improper/types") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "create_box improper/types", error); if (!atom->avec->impropers_allow) error->all(FLERR, "No impropers allowed with this atom style"); atom->nimpropertypes = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "extra/bond/per/atom") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "create_box extra/bond/per/atom", error); if (!atom->avec->bonds_allow) error->all(FLERR, "No bonds allowed with this atom style"); atom->bond_per_atom = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "extra/angle/per/atom") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "create_box extra/angle/per/atom", error); if (!atom->avec->angles_allow) error->all(FLERR, "No angles allowed with this atom style"); atom->angle_per_atom = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "extra/dihedral/per/atom") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "create_box extra/dihedral/per/atom", error); if (!atom->avec->dihedrals_allow) error->all(FLERR, "No dihedrals allowed with this atom style"); atom->dihedral_per_atom = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "extra/improper/per/atom") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "create_box extra/improper/per/atom", error); if (!atom->avec->impropers_allow) error->all(FLERR, "No impropers allowed with this atom style"); atom->improper_per_atom = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); iarg += 2; } else if (strcmp(arg[iarg], "extra/special/per/atom") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal create_box command"); + if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "create_box extra/special/per/atom", error); force->special_extra = utils::inumeric(FLERR, arg[iarg + 1], false, lmp); atom->maxspecial += force->special_extra; iarg += 2; } else - error->all(FLERR, "Illegal create_box command"); + error->all(FLERR, "Unknown create_box keyword: {}", arg[iarg]); } // problem setup using info from header diff --git a/src/domain.cpp b/src/domain.cpp index ebc468faed..7d60c20a24 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -1856,7 +1856,7 @@ const std::vector Domain::get_region_list() void Domain::set_boundary(int narg, char **arg, int flag) { - if (narg != 3) error->all(FLERR,"Illegal boundary command"); + if (narg != 3) error->all(FLERR,"Illegal boundary command: expected 3 argument but found {}", narg); char c; for (int idim = 0; idim < 3; idim++) @@ -1870,8 +1870,8 @@ void Domain::set_boundary(int narg, char **arg, int flag) else if (c == 's') boundary[idim][iside] = 2; else if (c == 'm') boundary[idim][iside] = 3; else { - if (flag == 0) error->all(FLERR,"Illegal boundary command"); - if (flag == 1) error->all(FLERR,"Illegal change_box command"); + if (flag == 0) error->all(FLERR,"Unknown boundary keyword: {}", c); + if (flag == 1) error->all(FLERR,"Unknown change_box keyword: {}", c); } } diff --git a/src/input.cpp b/src/input.cpp index 2979503d30..bb84a86e2c 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1351,7 +1351,7 @@ void Input::atom_modify() void Input::atom_style() { - if (narg < 1) error->all(FLERR,"Illegal atom_style command"); + if (narg < 1) utils::missing_cmd_args(FLERR, "atom_style", error); if (domain->box_exist) error->all(FLERR,"Atom_style command after simulation box is defined"); atom->create_avec(arg[0],narg-1,&arg[1],1); @@ -1488,12 +1488,12 @@ void Input::dihedral_style() void Input::dimension() { - if (narg != 1) error->all(FLERR,"Illegal dimension command"); + if (narg != 1) error->all(FLERR,"Illegal dimension command: expected 1 argument but found {}", narg); if (domain->box_exist) error->all(FLERR,"Dimension command after simulation box is defined"); domain->dimension = utils::inumeric(FLERR,arg[0],false,lmp); if (domain->dimension != 2 && domain->dimension != 3) - error->all(FLERR,"Illegal dimension command"); + error->all(FLERR, "Invalid dimension argument: {}", arg[0]); // must reset default extra_dof of all computes // since some were created before dimension command is encountered @@ -1948,7 +1948,7 @@ void Input::unfix() void Input::units() { - if (narg != 1) error->all(FLERR,"Illegal units command"); + if (narg != 1) error->all(FLERR,"Illegal units command: expected 1 argument but found {}", narg); if (domain->box_exist) error->all(FLERR,"Units command after simulation box is defined"); update->set_units(arg[0]); diff --git a/src/lattice.cpp b/src/lattice.cpp index be69fc1821..f88a55a4d5 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -36,7 +36,7 @@ Lattice::Lattice(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) // parse style arg - if (narg < 1) error->all(FLERR,"Illegal lattice command"); + if (narg < 1) utils::missing_cmd_args(FLERR, "lattice", error); if (strcmp(arg[0],"none") == 0) style = NONE; else if (strcmp(arg[0],"sc") == 0) style = SC; @@ -48,10 +48,10 @@ Lattice::Lattice(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) else if (strcmp(arg[0],"sq2") == 0) style = SQ2; else if (strcmp(arg[0],"hex") == 0) style = HEX; else if (strcmp(arg[0],"custom") == 0) style = CUSTOM; - else error->all(FLERR,"Illegal lattice command"); + else error->all(FLERR,"Unknown lattice keyword: {}", arg[0]); if (style == NONE) { - if (narg != 2) error->all(FLERR,"Illegal lattice command"); + if (narg != 2) error->all(FLERR,"Illegal lattice command: expected 2 argument but found {}", narg); // Domain creates a default lattice of style "none" // before Force class is instantiated, just use atof() in that case @@ -61,7 +61,7 @@ Lattice::Lattice(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) else xlattice = ylattice = zlattice = atof(arg[1]); - if (xlattice <= 0.0) error->all(FLERR,"Illegal lattice command"); + if (xlattice <= 0.0) error->all(FLERR, "Invalid lattice none argument: {}", arg[1]); return; } @@ -81,9 +81,9 @@ Lattice::Lattice(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) // scale = conversion factor between lattice and box units - if (narg < 2) error->all(FLERR,"Illegal lattice command"); + if (narg < 2) utils::missing_cmd_args(FLERR, "lattice", error); scale = utils::numeric(FLERR,arg[1],false,lmp); - if (scale <= 0.0) error->all(FLERR,"Illegal lattice command"); + if (scale <= 0.0) error->all(FLERR, "Invalid lattice {} argument: {}", arg[0], arg[1]); // set basis atoms for each style // x,y,z = fractional coords within unit cell @@ -148,23 +148,25 @@ Lattice::Lattice(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) int iarg = 2; while (iarg < narg) { if (strcmp(arg[iarg],"origin") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal lattice command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "lattice origin", error); origin[0] = utils::numeric(FLERR,arg[iarg+1],false,lmp); origin[1] = utils::numeric(FLERR,arg[iarg+2],false,lmp); origin[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); - if (origin[0] < 0.0 || origin[0] >= 1.0 || - origin[1] < 0.0 || origin[1] >= 1.0 || - origin[2] < 0.0 || origin[2] >= 1.0) - error->all(FLERR,"Illegal lattice command"); + if (origin[0] < 0.0 || origin[0] >= 1.0) + error->all(FLERR, "Invalid lattice origin argument: {}", origin[0]); + if (origin[1] < 0.0 || origin[1] >= 1.0) + error->all(FLERR, "Invalid lattice origin argument: {}", origin[1]); + if (origin[2] < 0.0 || origin[2] >= 1.0) + error->all(FLERR, "Invalid lattice origin argument: {}", origin[2]); iarg += 4; } else if (strcmp(arg[iarg],"orient") == 0) { - if (iarg+5 > narg) error->all(FLERR,"Illegal lattice command"); + if (iarg+5 > narg) utils::missing_cmd_args(FLERR, "lattice orient", error); int dim = -1; if (strcmp(arg[iarg+1],"x") == 0) dim = 0; else if (strcmp(arg[iarg+1],"y") == 0) dim = 1; else if (strcmp(arg[iarg+1],"z") == 0) dim = 2; - else error->all(FLERR,"Illegal lattice command"); + else error->all(FLERR,"Unknown lattice orient argument: {}", arg[iarg+1]); int *orient = nullptr; if (dim == 0) orient = orientx; else if (dim == 1) orient = orienty; @@ -175,7 +177,7 @@ Lattice::Lattice(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) iarg += 5; } else if (strcmp(arg[iarg],"spacing") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal lattice command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "lattice spacing", error); spaceflag = 1; xlattice = utils::numeric(FLERR,arg[iarg+1],false,lmp); ylattice = utils::numeric(FLERR,arg[iarg+2],false,lmp); @@ -183,46 +185,50 @@ Lattice::Lattice(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) iarg += 4; } else if (strcmp(arg[iarg],"a1") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal lattice command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "lattice a1", error); if (style != CUSTOM) error->all(FLERR, - "Invalid option in lattice command for non-custom style"); + "Invalid a1 in lattice command for non-custom style"); a1[0] = utils::numeric(FLERR,arg[iarg+1],false,lmp); a1[1] = utils::numeric(FLERR,arg[iarg+2],false,lmp); a1[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); iarg += 4; } else if (strcmp(arg[iarg],"a2") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal lattice command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "lattice a2", error); if (style != CUSTOM) error->all(FLERR, - "Invalid option in lattice command for non-custom style"); + "Invalid a2 option in lattice command for non-custom style"); a2[0] = utils::numeric(FLERR,arg[iarg+1],false,lmp); a2[1] = utils::numeric(FLERR,arg[iarg+2],false,lmp); a2[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); iarg += 4; } else if (strcmp(arg[iarg],"a3") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal lattice command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "lattice a3", error); if (style != CUSTOM) error->all(FLERR, - "Invalid option in lattice command for non-custom style"); + "Invalid a3 option in lattice command for non-custom style"); a3[0] = utils::numeric(FLERR,arg[iarg+1],false,lmp); a3[1] = utils::numeric(FLERR,arg[iarg+2],false,lmp); a3[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); iarg += 4; } else if (strcmp(arg[iarg],"basis") == 0) { - if (iarg+4 > narg) error->all(FLERR,"Illegal lattice command"); + if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "lattice basis", error); if (style != CUSTOM) error->all(FLERR, - "Invalid option in lattice command for non-custom style"); + "Invalid basis option in lattice command for non-custom style"); double x = utils::numeric(FLERR,arg[iarg+1],false,lmp); double y = utils::numeric(FLERR,arg[iarg+2],false,lmp); double z = utils::numeric(FLERR,arg[iarg+3],false,lmp); - if (x < 0.0 || x >= 1.0 || y < 0.0 || y >= 1.0 || z < 0.0 || z >= 1.0) - error->all(FLERR,"Illegal lattice command"); + if (x < 0.0 || x >= 1.0) + error->all(FLERR, "Invalid lattice basis argument: {}", x); + if (y < 0.0 || y >= 1.0) + error->all(FLERR, "Invalid lattice basis argument: {}", y); + if (z < 0.0 || z >= 1.0) + error->all(FLERR, "Invalid lattice basis argument: {}", z); add_basis(x,y,z); iarg += 4; - } else error->all(FLERR,"Illegal lattice command"); + } else error->all(FLERR,"Unknown lattice keyword: {}", arg[iarg]); } // check settings for errors diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 9e74ad3809..ab77e15a4b 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -2533,10 +2533,10 @@ void Neighbor::build_one(class NeighList *mylist, int preflag) void Neighbor::set(int narg, char **arg) { - if (narg != 2) error->all(FLERR,"Illegal neighbor command"); + if (narg != 2) error->all(FLERR,"Illegal neighbor command: expected 2 argument but found {}", narg); skin = utils::numeric(FLERR,arg[0],false,lmp); - if (skin < 0.0) error->all(FLERR,"Illegal neighbor command"); + if (skin < 0.0) error->all(FLERR, "Invalid neighbor argument: {}", arg[0]); if (strcmp(arg[1],"nsq") == 0) style = Neighbor::NSQ; else if (strcmp(arg[1],"bin") == 0) style = Neighbor::BIN; @@ -2544,7 +2544,7 @@ void Neighbor::set(int narg, char **arg) style = Neighbor::MULTI; ncollections = atom->ntypes; } else if (strcmp(arg[1],"multi/old") == 0) style = Neighbor::MULTI_OLD; - else error->all(FLERR,"Illegal neighbor command"); + else error->all(FLERR,"Unknown neighbor {} argument: {}", arg[0], arg[1]); if (style == Neighbor::MULTI_OLD && lmp->citeme) lmp->citeme->add(cite_neigh_multi_old); if (style == Neighbor::MULTI && lmp->citeme) lmp->citeme->add(cite_neigh_multi); From 5ff56753dafb63c74005e33e8b3e7b8f07e7032b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 17 Aug 2022 23:56:22 -0400 Subject: [PATCH 2/8] update unit tests for changed error messages --- src/lattice.cpp | 2 +- unittest/commands/test_lattice_region.cpp | 28 +++++++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/lattice.cpp b/src/lattice.cpp index f88a55a4d5..14901dfa21 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -188,7 +188,7 @@ Lattice::Lattice(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "lattice a1", error); if (style != CUSTOM) error->all(FLERR, - "Invalid a1 in lattice command for non-custom style"); + "Invalid a1 option in lattice command for non-custom style"); a1[0] = utils::numeric(FLERR,arg[iarg+1],false,lmp); a1[1] = utils::numeric(FLERR,arg[iarg+2],false,lmp); a1[2] = utils::numeric(FLERR,arg[iarg+3],false,lmp); diff --git a/unittest/commands/test_lattice_region.cpp b/unittest/commands/test_lattice_region.cpp index 4f314b1669..cc22509dcd 100644 --- a/unittest/commands/test_lattice_region.cpp +++ b/unittest/commands/test_lattice_region.cpp @@ -45,7 +45,9 @@ protected: { testbinary = "LatticeRegionTest"; LAMMPSTest::SetUp(); - command("units metal"); + HIDE_OUTPUT([&] { + command("units metal"); + }); } }; @@ -63,7 +65,7 @@ TEST_F(LatticeRegionTest, lattice_none) ASSERT_EQ(lattice->basis, nullptr); TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice");); - TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice xxx");); + TEST_FAILURE(".*ERROR: Unknown lattice keyword: xxx.*", command("lattice xxx");); TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice none 1.0 origin");); TEST_FAILURE(".*ERROR: Expected floating point.*", command("lattice none xxx");); @@ -114,10 +116,11 @@ TEST_F(LatticeRegionTest, lattice_sc) ASSERT_EQ(lattice->basis[0][1], 0.0); ASSERT_EQ(lattice->basis[0][2], 0.0); - TEST_FAILURE(".*ERROR: Illegal lattice command.*", + TEST_FAILURE(".*ERROR: Invalid lattice origin argument: 1.*", command("lattice sc 1.0 origin 1.0 1.0 1.0");); - TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice sc 1.0 origin 1.0");); - TEST_FAILURE(".*ERROR: Illegal lattice command.*", + TEST_FAILURE(".*ERROR: Illegal lattice origin command: missing argument.*", + command("lattice sc 1.0 origin 1.0");); + TEST_FAILURE(".*ERROR: Unknown lattice keyword: xxx.*", command("lattice sc 1.0 origin 0.0 0.0 0.0 xxx");); TEST_FAILURE(".*ERROR: Expected floating point.*", command("lattice sc 1.0 origin xxx 1.0 1.0");); @@ -195,11 +198,12 @@ TEST_F(LatticeRegionTest, lattice_fcc) ASSERT_EQ(lattice->basis[3][1], 0.5); ASSERT_EQ(lattice->basis[3][2], 0.5); - TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*", + TEST_FAILURE(".*ERROR: Invalid basis option in lattice command for non-custom style.*", command("lattice fcc 1.0 basis 0.0 0.0 0.0");); - TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*", + TEST_FAILURE(".*ERROR: Invalid a1 option in lattice command for non-custom style.*", command("lattice fcc 1.0 a1 0.0 1.0 0.0");); - TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice fcc 1.0 orient w 1 0 0");); + TEST_FAILURE(".*ERROR: Unknown lattice orient argument: w.*", + command("lattice fcc 1.0 orient w 1 0 0");); BEGIN_HIDE_OUTPUT(); command("dimension 2"); @@ -241,9 +245,9 @@ TEST_F(LatticeRegionTest, lattice_hcp) ASSERT_EQ(lattice->a3[1], 0.0); ASSERT_DOUBLE_EQ(lattice->a3[2], sqrt(8.0 / 3.0)); - TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*", + TEST_FAILURE(".*ERROR: Invalid a2 option in lattice command for non-custom style.*", command("lattice hcp 1.0 a2 0.0 1.0 0.0");); - TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*", + TEST_FAILURE(".*ERROR: Invalid a3 option in lattice command for non-custom style.*", command("lattice hcp 1.0 a3 0.0 1.0 0.0");); BEGIN_HIDE_OUTPUT(); command("dimension 2"); @@ -452,9 +456,9 @@ TEST_F(LatticeRegionTest, lattice_custom) ASSERT_DOUBLE_EQ(lattice->a3[1], 0.0); ASSERT_DOUBLE_EQ(lattice->a3[2], 4.34 * sqrt(8.0 / 3.0)); - TEST_FAILURE(".*ERROR: Illegal lattice command.*", + TEST_FAILURE(".*ERROR: Invalid lattice basis argument: -0.1.*", command("lattice custom 1.0 basis -0.1 0 0");); - TEST_FAILURE(".*ERROR: Illegal lattice command.*", + TEST_FAILURE(".*ERROR: Invalid lattice basis argument: 1.*", command("lattice custom 1.0 basis 0.0 1.0 0");); BEGIN_HIDE_OUTPUT(); From ff9c02f0535a57d0659d314ac058d180b55e246f Mon Sep 17 00:00:00 2001 From: Jiancheng Chen <2742581175@qq.com> Date: Thu, 18 Aug 2022 21:08:36 +0800 Subject: [PATCH 3/8] improved error messages in pair and input.cpp --- src/domain.cpp | 2 +- src/input.cpp | 46 +++++++++++++++++++++++----------------------- src/lattice.cpp | 2 +- src/neighbor.cpp | 2 +- src/pair.cpp | 24 ++++++++++++------------ 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/domain.cpp b/src/domain.cpp index 7d60c20a24..d3d6985f99 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -1856,7 +1856,7 @@ const std::vector Domain::get_region_list() void Domain::set_boundary(int narg, char **arg, int flag) { - if (narg != 3) error->all(FLERR,"Illegal boundary command: expected 3 argument but found {}", narg); + if (narg != 3) error->all(FLERR,"Illegal boundary command: expected 3 arguments but found {}", narg); char c; for (int idim = 0; idim < 3; idim++) diff --git a/src/input.cpp b/src/input.cpp index bb84a86e2c..f11cb5177b 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -860,7 +860,7 @@ int Input::execute_command() void Input::clear() { - if (narg > 0) error->all(FLERR,"Illegal clear command"); + if (narg > 0) error->all(FLERR,"Illegal clear command: unexpected arguments but found {}", narg); lmp->destroy(); lmp->create(); lmp->post_create(); @@ -870,7 +870,7 @@ void Input::clear() void Input::echo() { - if (narg != 1) error->all(FLERR,"Illegal echo command"); + if (narg != 1) error->all(FLERR,"Illegal echo command: expected 1 argument but found {}", narg); if (strcmp(arg[0],"none") == 0) { echo_screen = 0; @@ -884,14 +884,14 @@ void Input::echo() } else if (strcmp(arg[0],"both") == 0) { echo_screen = 1; echo_log = 1; - } else error->all(FLERR,"Illegal echo command"); + } else error->all(FLERR,"Unknown echo keyword: {}", arg[0]); } /* ---------------------------------------------------------------------- */ void Input::ifthenelse() { - if (narg < 3) error->all(FLERR,"Illegal if command"); + if (narg < 3) utils::missing_cmd_args(FLERR, "if", error); // substitute for variables in Boolean expression for "if" // in case expression was enclosed in quotes @@ -908,7 +908,7 @@ void Input::ifthenelse() // bound "then" commands - if (strcmp(arg[1],"then") != 0) error->all(FLERR,"Illegal if command"); + if (strcmp(arg[1],"then") != 0) error->all(FLERR,"Illegal if command: expected \"then\" but found \"{}\"", arg[1]); int first = 2; int iarg = first; @@ -923,13 +923,13 @@ void Input::ifthenelse() if (btest != 0.0) { int ncommands = last-first + 1; - if (ncommands <= 0) error->all(FLERR,"Illegal if command"); + if (ncommands <= 0) utils::missing_cmd_args(FLERR, "if then", error); auto commands = new char*[ncommands]; ncommands = 0; for (int i = first; i <= last; i++) { n = strlen(arg[i]) + 1; - if (n == 1) error->all(FLERR,"Illegal if command"); + if (n == 1) error->all(FLERR,"Illegal if then command: execute command is empty"); commands[ncommands] = new char[n]; strcpy(commands[ncommands],arg[i]); ncommands++; @@ -954,7 +954,7 @@ void Input::ifthenelse() // bound and execute "elif" or "else" commands while (iarg != narg) { - if (iarg+2 > narg) error->all(FLERR,"Illegal if command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "if then", error); if (strcmp(arg[iarg],"elif") == 0) { n = strlen(arg[iarg+1]) + 1; if (n > maxline) reallocate(line,maxline,n); @@ -976,13 +976,13 @@ void Input::ifthenelse() if (btest == 0.0) continue; int ncommands = last-first + 1; - if (ncommands <= 0) error->all(FLERR,"Illegal if command"); + if (ncommands <= 0) utils::missing_cmd_args(FLERR, "if elif/else", error); auto commands = new char*[ncommands]; ncommands = 0; for (int i = first; i <= last; i++) { n = strlen(arg[i]) + 1; - if (n == 1) error->all(FLERR,"Illegal if command"); + if (n == 1) error->all(FLERR,"Illegal if elif/else command: execute command is empty"); commands[ncommands] = new char[n]; strcpy(commands[ncommands],arg[i]); ncommands++; @@ -1038,7 +1038,7 @@ void Input::include() void Input::jump() { - if (narg < 1 || narg > 2) error->all(FLERR,"Illegal jump command"); + if (narg < 1 || narg > 2) error->all(FLERR,"Illegal jump command: expected 1 or 2 argument(s) but found {}", narg); if (jump_skip) { jump_skip = 0; @@ -1069,7 +1069,7 @@ void Input::jump() void Input::label() { - if (narg != 1) error->all(FLERR,"Illegal label command"); + if (narg != 1) error->all(FLERR,"Illegal label command: expected 1 argument but found {}", narg); if (label_active && strcmp(labelstr,arg[0]) == 0) label_active = 0; } @@ -1077,12 +1077,12 @@ void Input::label() void Input::log() { - if ((narg < 1) || (narg > 2)) error->all(FLERR,"Illegal log command"); + if ((narg < 1) || (narg > 2)) error->all(FLERR,"Illegal log command: expected 1 or 2 argument(s) but found {}", narg); int appendflag = 0; if (narg == 2) { if (strcmp(arg[1],"append") == 0) appendflag = 1; - else error->all(FLERR,"Illegal log command"); + else error->all(FLERR,"Unknown log keyword: {}", arg[1]); } if (me == 0) { @@ -1112,7 +1112,7 @@ void Input::next_command() void Input::partition() { - if (narg < 3) error->all(FLERR,"Illegal partition command"); + if (narg < 3) utils::missing_cmd_args(FLERR, "partition", error); int ilo,ihi; int yesflag = utils::logical(FLERR,arg[0],false,lmp); @@ -1138,7 +1138,7 @@ void Input::partition() void Input::print() { - if (narg < 1) error->all(FLERR,"Illegal print command"); + if (narg < 1) utils::missing_cmd_args(FLERR, "print", error); // copy 1st arg back into line (copy is being used) // check maxline since arg[0] could have been expanded by variables @@ -1158,7 +1158,7 @@ void Input::print() int iarg = 1; while (iarg < narg) { if (strcmp(arg[iarg],"file") == 0 || strcmp(arg[iarg],"append") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal print command"); + if (iarg+2 > narg) error->all(FLERR,"Illegal print {} command: missing argument(s)", arg[iarg]); if (me == 0) { if (fp != nullptr) fclose(fp); if (strcmp(arg[iarg],"file") == 0) fp = fopen(arg[iarg+1],"w"); @@ -1168,14 +1168,14 @@ void Input::print() } iarg += 2; } else if (strcmp(arg[iarg],"screen") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal print command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "print screen", error); screenflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"universe") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal print command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "print universe", error); universeflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; - } else error->all(FLERR,"Illegal print command"); + } else error->all(FLERR,"Unknown print keyword: {}", arg[iarg]); } if (me == 0) { @@ -1205,7 +1205,7 @@ void Input::quit() { if (narg == 0) error->done(0); // 1 would be fully backwards compatible if (narg == 1) error->done(utils::inumeric(FLERR,arg[0],false,lmp)); - error->all(FLERR,"Illegal quit command"); + error->all(FLERR,"Illegal quit command: expected 0 or 1 argument but found {}", narg); } /* ---------------------------------------------------------------------- */ @@ -1589,7 +1589,7 @@ void Input::lattice() void Input::mass() { - if (narg != 2) error->all(FLERR,"Illegal mass command"); + if (narg != 2) error->all(FLERR,"Illegal mass command: expected 2 arguments but found {}", narg); if (domain->box_exist == 0) error->all(FLERR,"Mass command before simulation box is defined"); atom->set_mass(FLERR,narg,arg); @@ -1731,7 +1731,7 @@ void Input::pair_modify() void Input::pair_style() { - if (narg < 1) error->all(FLERR,"Illegal pair_style command"); + if (narg < 1) utils::missing_cmd_args(FLERR, "pair_style", error); if (force->pair) { std::string style = arg[0]; int match = 0; diff --git a/src/lattice.cpp b/src/lattice.cpp index f88a55a4d5..8ba74d52d6 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -51,7 +51,7 @@ Lattice::Lattice(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) else error->all(FLERR,"Unknown lattice keyword: {}", arg[0]); if (style == NONE) { - if (narg != 2) error->all(FLERR,"Illegal lattice command: expected 2 argument but found {}", narg); + if (narg != 2) error->all(FLERR,"Illegal lattice command: expected 2 arguments but found {}", narg); // Domain creates a default lattice of style "none" // before Force class is instantiated, just use atof() in that case diff --git a/src/neighbor.cpp b/src/neighbor.cpp index ec97f4dced..e5e378ff6b 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -2527,7 +2527,7 @@ void Neighbor::build_one(class NeighList *mylist, int preflag) void Neighbor::set(int narg, char **arg) { - if (narg != 2) error->all(FLERR,"Illegal neighbor command: expected 2 argument but found {}", narg); + if (narg != 2) error->all(FLERR,"Illegal neighbor command: expected 2 arguments but found {}", narg); skin = utils::numeric(FLERR,arg[0],false,lmp); if (skin < 0.0) error->all(FLERR, "Invalid neighbor argument: {}", arg[0]); diff --git a/src/pair.cpp b/src/pair.cpp index 4d42035fd1..81f231bb31 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -159,57 +159,57 @@ Pair::~Pair() void Pair::modify_params(int narg, char **arg) { - if (narg == 0) error->all(FLERR,"Illegal pair_modify command"); + if (narg == 0) utils::missing_cmd_args(FLERR, "pair_modify", error); int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg],"mix") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal pair_modify command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "pair_modify mix", error); if (strcmp(arg[iarg+1],"geometric") == 0) mix_flag = GEOMETRIC; else if (strcmp(arg[iarg+1],"arithmetic") == 0) mix_flag = ARITHMETIC; else if (strcmp(arg[iarg+1],"sixthpower") == 0) mix_flag = SIXTHPOWER; - else error->all(FLERR,"Illegal pair_modify command"); + else error->all(FLERR,"Unknown pair_modify mix argument: {}", arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"shift") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal pair_modify command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "pair_modify shift", error); offset_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"table") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal pair_modify command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "pair_modify table", error); ncoultablebits = utils::inumeric(FLERR,arg[iarg+1],false,lmp); if (ncoultablebits > (int)sizeof(float)*CHAR_BIT) error->all(FLERR,"Too many total bits for bitmapped lookup table"); iarg += 2; } else if (strcmp(arg[iarg],"table/disp") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal pair_modify command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "pair_modify table/disp", error); ndisptablebits = utils::inumeric(FLERR,arg[iarg+1],false,lmp); if (ndisptablebits > (int)sizeof(float)*CHAR_BIT) error->all(FLERR,"Too many total bits for bitmapped lookup table"); iarg += 2; } else if (strcmp(arg[iarg],"tabinner") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal pair_modify command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "pair_modify tabinner", error); tabinner = utils::numeric(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"tabinner/disp") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal pair_modify command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "pair_modify tabinner/disp", error); tabinner_disp = utils::numeric(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"tail") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal pair_modify command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "pair_modify tail", error); tail_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"compute") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal pair_modify command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "pair_modify compute", error); compute_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"nofdotr") == 0) { no_virial_fdotr_compute = 1; ++iarg; } else if (strcmp(arg[iarg],"neigh/trim") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal pair_modify command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "pair_modify neigh/trim", error); trim_flag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; - } else error->all(FLERR,"Illegal pair_modify command"); + } else error->all(FLERR,"Unknown pair_modify keyword: {}", arg[iarg]); } } From 9edb1ee928976ba7fabe5400dd233570b085563c Mon Sep 17 00:00:00 2001 From: Jiancheng Chen <2742581175@qq.com> Date: Thu, 18 Aug 2022 21:14:39 +0800 Subject: [PATCH 4/8] improved error messages in input.cpp --- src/input.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index f11cb5177b..ef125d3145 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1214,10 +1214,10 @@ void Input::shell() { int rv,err; - if (narg < 1) error->all(FLERR,"Illegal shell command"); + if (narg < 1) utils::missing_cmd_args(FLERR, "shell", error); if (strcmp(arg[0],"cd") == 0) { - if (narg != 2) error->all(FLERR,"Illegal shell cd command"); + if (narg != 2) error->all(FLERR,"Illegal shell command: expected 2 argument but found {}", narg); rv = (platform::chdir(arg[1]) < 0) ? errno : 0; MPI_Reduce(&rv,&err,1,MPI_INT,MPI_MAX,0,world); errno = err; @@ -1225,7 +1225,7 @@ void Input::shell() error->warning(FLERR, "Shell command 'cd {}' failed with error '{}'", arg[1], utils::getsyserror()); } } else if (strcmp(arg[0],"mkdir") == 0) { - if (narg < 2) error->all(FLERR,"Illegal shell mkdir command"); + if (narg < 2) utils::missing_cmd_args(FLERR, "shell mkdir", error); if (me == 0) { for (int i = 1; i < narg; i++) { rv = (platform::mkdir(arg[i]) < 0) ? errno : 0; @@ -1235,7 +1235,7 @@ void Input::shell() } } } else if (strcmp(arg[0],"mv") == 0) { - if (narg != 3) error->all(FLERR,"Illegal shell mv command"); + if (narg != 3) error->all(FLERR,"Illegal shell command: expected 3 argument but found {}", narg); if (me == 0) { if (platform::path_is_directory(arg[2])) { if (system(fmt::format("mv {} {}", arg[1], arg[2]).c_str())) @@ -1248,7 +1248,7 @@ void Input::shell() } } } else if (strcmp(arg[0],"rm") == 0) { - if (narg < 2) error->all(FLERR,"Illegal shell rm command"); + if (narg < 2) utils::missing_cmd_args(FLERR, "shell rm", error); if (me == 0) { int i = 1; bool warn = true; @@ -1264,7 +1264,7 @@ void Input::shell() } } } else if (strcmp(arg[0],"rmdir") == 0) { - if (narg < 2) error->all(FLERR,"Illegal shell rmdir command"); + if (narg < 2) utils::missing_cmd_args(FLERR, "shell rmdir", error); if (me == 0) { for (int i = 1; i < narg; i++) { if (platform::rmdir(arg[i]) < 0) @@ -1273,7 +1273,7 @@ void Input::shell() } } } else if (strcmp(arg[0],"putenv") == 0) { - if (narg < 2) error->all(FLERR,"Illegal shell putenv command"); + if (narg < 2) utils::missing_cmd_args(FLERR, "shell putenv", error); for (int i = 1; i < narg; i++) { rv = 0; if (arg[i]) rv = platform::putenv(arg[i]); From 414b0b14756b8848f8d981542236c53c04d87e7d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Aug 2022 10:52:25 -0400 Subject: [PATCH 5/8] update unit tests --- unittest/commands/test_simple_commands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index c58efcd9ea..2563c09848 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -81,7 +81,7 @@ TEST_F(SimpleCommandsTest, Echo) ASSERT_EQ(lmp->input->echo_log, 1); TEST_FAILURE(".*ERROR: Illegal echo command.*", command("echo");); - TEST_FAILURE(".*ERROR: Illegal echo command.*", command("echo xxx");); + TEST_FAILURE(".*ERROR: Unknown echo keyword: xxx.*", command("echo xxx");); } TEST_F(SimpleCommandsTest, Log) From 3ec06dd2c25418ca0afd9f243599ff91a7d2575e Mon Sep 17 00:00:00 2001 From: Jiancheng Chen <2742581175@qq.com> Date: Fri, 19 Aug 2022 21:06:00 +0800 Subject: [PATCH 6/8] improve some error messages in comm, domain and region.cpp --- src/comm.cpp | 32 ++++++++++++++++---------------- src/domain.cpp | 10 +++++----- src/region.cpp | 16 ++++++++-------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/comm.cpp b/src/comm.cpp index 5175af28e5..1679cc3c41 100644 --- a/src/comm.cpp +++ b/src/comm.cpp @@ -282,12 +282,12 @@ void Comm::init_exchange() void Comm::modify_params(int narg, char **arg) { - if (narg < 1) error->all(FLERR,"Illegal comm_modify command"); + if (narg < 1) utils::missing_cmd_args(FLERR, "comm_modify", error); int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg],"mode") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal comm_modify command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "comm_modify mode", error); if (strcmp(arg[iarg+1],"single") == 0) { // need to reset cutghostuser when switching comm mode if (mode == Comm::MULTI) cutghostuser = 0.0; @@ -311,26 +311,27 @@ void Comm::modify_params(int narg, char **arg) if (mode == Comm::MULTI) cutghostuser = 0.0; memory->destroy(cutusermulti); mode = Comm::MULTIOLD; - } else error->all(FLERR,"Illegal comm_modify command"); + } else error->all(FLERR,"Unknown comm_modify mode argument: {}", arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"group") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal comm_modify command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "comm_modify group", error); bordergroup = group->find(arg[iarg+1]); if (bordergroup < 0) - error->all(FLERR,"Invalid group in comm_modify command"); - if (bordergroup && (atom->firstgroupname == nullptr || - strcmp(arg[iarg+1],atom->firstgroupname) != 0)) - error->all(FLERR,"Comm_modify group != atom_modify first group"); + error->all(FLERR, "Invalid comm_modify keyword: group {} not found", arg[iarg+1]); + if (atom->firstgroupname == nullptr) + error->all(FLERR, "Invalid comm_modify keyword: atom_modify first command must be used"); + if (strcmp(arg[iarg+1],atom->firstgroupname) != 0) + error->all(FLERR, "comm_modify group != atom_modify first group: {}", atom->firstgroupname); iarg += 2; } else if (strcmp(arg[iarg],"cutoff") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal comm_modify command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "comm_modify cutoff", error); if (mode == Comm::MULTI) error->all(FLERR, "Use cutoff/multi keyword to set cutoff in multi mode"); if (mode == Comm::MULTIOLD) error->all(FLERR, "Use cutoff/multi/old keyword to set cutoff in multi mode"); cutghostuser = utils::numeric(FLERR,arg[iarg+1],false,lmp); if (cutghostuser < 0.0) - error->all(FLERR,"Invalid cutoff in comm_modify command"); + error->all(FLERR,"Invalid cutoff {} in comm_modify command", arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"cutoff/multi") == 0) { int i,nlo,nhi; @@ -355,7 +356,7 @@ void Comm::modify_params(int narg, char **arg) cut = utils::numeric(FLERR,arg[iarg+2],false,lmp); cutghostuser = MAX(cutghostuser,cut); if (cut < 0.0) - error->all(FLERR,"Invalid cutoff in comm_modify command"); + error->all(FLERR,"Invalid cutoff {} in comm_modify command", arg[iarg+2]); // collections use 1-based indexing externally and 0-based indexing internally for (i=nlo; i<=nhi; ++i) cutusermulti[i-1] = cut; @@ -370,8 +371,7 @@ void Comm::modify_params(int narg, char **arg) if (domain->box_exist == 0) error->all(FLERR, "Cannot set cutoff/multi before simulation box is defined"); const int ntypes = atom->ntypes; - if (iarg+3 > narg) - error->all(FLERR,"Illegal comm_modify command"); + if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "comm_modify cutoff/multi/old", error); if (cutusermultiold == nullptr) { memory->create(cutusermultiold,ntypes+1,"comm:cutusermultiold"); for (i=0; i < ntypes+1; ++i) @@ -381,7 +381,7 @@ void Comm::modify_params(int narg, char **arg) cut = utils::numeric(FLERR,arg[iarg+2],false,lmp); cutghostuser = MAX(cutghostuser,cut); if (cut < 0.0) - error->all(FLERR,"Invalid cutoff in comm_modify command"); + error->all(FLERR,"Invalid cutoff {} in comm_modify command", arg[iarg+2]); for (i=nlo; i<=nhi; ++i) cutusermultiold[i] = cut; iarg += 3; @@ -391,10 +391,10 @@ void Comm::modify_params(int narg, char **arg) multi_reduce = 1; iarg += 1; } else if (strcmp(arg[iarg],"vel") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal comm_modify command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "comm_modify vel", error); ghost_velocity = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; - } else error->all(FLERR,"Illegal comm_modify command"); + } else error->all(FLERR,"Unknown comm_modify keyword: {}", arg[iarg]); } } diff --git a/src/domain.cpp b/src/domain.cpp index d3d6985f99..4d299fb7bf 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -1744,7 +1744,7 @@ void Domain::set_lattice(int narg, char **arg) void Domain::add_region(int narg, char **arg) { - if (narg < 2) error->all(FLERR,"Illegal region command"); + if (narg < 2) utils::missing_cmd_args(FLERR, "region", error); if (strcmp(arg[1],"delete") == 0) { delete_region(arg[0]); @@ -1935,17 +1935,17 @@ void Domain::set_boundary(int narg, char **arg, int flag) void Domain::set_box(int narg, char **arg) { - if (narg < 1) error->all(FLERR,"Illegal box command"); + if (narg < 1) utils::missing_cmd_args(FLERR, "box", error); int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg],"tilt") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal box command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "box tilt", error); if (strcmp(arg[iarg+1],"small") == 0) tiltsmall = 1; else if (strcmp(arg[iarg+1],"large") == 0) tiltsmall = 0; - else error->all(FLERR,"Illegal box command"); + else error->all(FLERR,"Unknown box tilt argument: {}", arg[iarg+1]); iarg += 2; - } else error->all(FLERR,"Illegal box command"); + } else error->all(FLERR,"Unknown box keyword: {}", arg[iarg]); } } diff --git a/src/region.cpp b/src/region.cpp index 307513add6..d63fe25017 100644 --- a/src/region.cpp +++ b/src/region.cpp @@ -66,27 +66,27 @@ void Region::init() { if (xstr) { xvar = input->variable->find(xstr); - if (xvar < 0) error->all(FLERR, "Variable name for region does not exist"); + if (xvar < 0) error->all(FLERR, "Variable {} for region does not exist", xstr); if (!input->variable->equalstyle(xvar)) - error->all(FLERR, "Variable for region is invalid style"); + error->all(FLERR, "Variable {} for region is invalid style", xstr); } if (ystr) { yvar = input->variable->find(ystr); - if (yvar < 0) error->all(FLERR, "Variable name for region does not exist"); + if (yvar < 0) error->all(FLERR, "Variable {} for region does not exist", ystr); if (!input->variable->equalstyle(yvar)) - error->all(FLERR, "Variable for region is not equal style"); + error->all(FLERR, "Variable {} for region is not equal style", ystr); } if (zstr) { zvar = input->variable->find(zstr); - if (zvar < 0) error->all(FLERR, "Variable name for region does not exist"); + if (zvar < 0) error->all(FLERR, "Variable {} for region does not exist", zstr); if (!input->variable->equalstyle(zvar)) - error->all(FLERR, "Variable for region is not equal style"); + error->all(FLERR, "Variable {} for region is not equal style", zstr); } if (tstr) { tvar = input->variable->find(tstr); - if (tvar < 0) error->all(FLERR, "Variable name for region does not exist"); + if (tvar < 0) error->all(FLERR, "Variable {} for region does not exist", tstr); if (!input->variable->equalstyle(tvar)) - error->all(FLERR, "Variable for region is not equal style"); + error->all(FLERR, "Variable {} for region is not equal style", tstr); } vel_timestep = -1; } From 59837dd44bf8b716d10fb154beaa96909146cf3a Mon Sep 17 00:00:00 2001 From: Jiancheng Chen <2742581175@qq.com> Date: Thu, 25 Aug 2022 11:09:21 +0800 Subject: [PATCH 7/8] improve error messages in run and variable.cpp --- src/run.cpp | 26 +++++++++++++------------- src/variable.cpp | 47 +++++++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/run.cpp b/src/run.cpp index a026580c83..3a9a4dc32e 100644 --- a/src/run.cpp +++ b/src/run.cpp @@ -36,7 +36,7 @@ Run::Run(LAMMPS *lmp) : Command(lmp) {} void Run::command(int narg, char **arg) { - if (narg < 1) error->all(FLERR,"Illegal run command"); + if (narg < 1) utils::missing_cmd_args(FLERR, "run", error); if (domain->box_exist == 0) error->all(FLERR,"Run command before simulation box is defined"); @@ -62,25 +62,25 @@ void Run::command(int narg, char **arg) int iarg = 1; while (iarg < narg) { if (strcmp(arg[iarg],"upto") == 0) { - if (iarg+1 > narg) error->all(FLERR,"Illegal run command"); + if (iarg+1 > narg) utils::missing_cmd_args(FLERR, "run upto", error); uptoflag = 1; iarg += 1; } else if (strcmp(arg[iarg],"start") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "run start", error); startflag = 1; start = utils::bnumeric(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"stop") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "run stop", error); stopflag = 1; stop = utils::bnumeric(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"pre") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "run pre", error); preflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; } else if (strcmp(arg[iarg],"post") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal run command"); + if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "run post", error); postflag = utils::logical(FLERR,arg[iarg+1],false,lmp); iarg += 2; @@ -89,15 +89,15 @@ void Run::command(int narg, char **arg) // set ncommands = 0 if single command and it is "NULL" } else if (strcmp(arg[iarg],"every") == 0) { - if (iarg+3 > narg) error->all(FLERR,"Illegal run command"); + if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "run every", error); nevery = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - if (nevery <= 0) error->all(FLERR,"Illegal run command"); + if (nevery <= 0) error->all(FLERR, "Invalid run every argument: {}", nevery); first = iarg+2; last = narg-1; ncommands = last-first + 1; if (ncommands == 1 && strcmp(arg[first],"NULL") == 0) ncommands = 0; iarg = narg; - } else error->all(FLERR,"Illegal run command"); + } else error->all(FLERR,"Unknown run keyword: {}", arg[iarg]); } // set nsteps as integer, using upto value if specified @@ -105,12 +105,12 @@ void Run::command(int narg, char **arg) int nsteps; if (!uptoflag) { if (nsteps_input < 0 || nsteps_input > MAXSMALLINT) - error->all(FLERR,"Invalid run command N value"); + error->all(FLERR,"Invalid run command N value: {}", nsteps_input); nsteps = static_cast (nsteps_input); } else { bigint delta = nsteps_input - update->ntimestep; if (delta < 0 || delta > MAXSMALLINT) - error->all(FLERR,"Invalid run command upto value"); + error->all(FLERR,"Invalid run command upto value: {}", delta); nsteps = static_cast (delta); } @@ -118,13 +118,13 @@ void Run::command(int narg, char **arg) if (startflag) { if (start < 0) - error->all(FLERR,"Invalid run command start/stop value"); + error->all(FLERR,"Invalid run command start value: {}", start); if (start > update->ntimestep) error->all(FLERR,"Run command start value is after start of run"); } if (stopflag) { if (stop < 0) - error->all(FLERR,"Invalid run command start/stop value"); + error->all(FLERR,"Invalid run command stop value: {}", stop); if (stop < update->ntimestep + nsteps) error->all(FLERR,"Run command stop value is before end of run"); } diff --git a/src/variable.cpp b/src/variable.cpp index a564847b68..d6eec9eeb3 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -162,7 +162,7 @@ Variable::~Variable() void Variable::set(int narg, char **arg) { - if (narg < 2) error->all(FLERR,"Illegal variable command"); + if (narg < 2) utils::missing_cmd_args(FLERR, "variable", error); int replaceflag = 0; @@ -170,7 +170,7 @@ void Variable::set(int narg, char **arg) // doesn't matter if variable no longer exists if (strcmp(arg[1],"delete") == 0) { - if (narg != 2) error->all(FLERR,"Illegal variable command"); + if (narg != 2) error->all(FLERR,"Illegal variable command: expected 2 argument but found {}", narg); if (find(arg[0]) >= 0) remove(find(arg[0])); return; @@ -178,7 +178,7 @@ void Variable::set(int narg, char **arg) // num = listed args, which = 1st value, data = copied args } else if (strcmp(arg[1],"index") == 0) { - if (narg < 3) error->all(FLERR,"Illegal variable command"); + if (narg < 3) utils::missing_cmd_args(FLERR, "variable index", error); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = INDEX; @@ -193,6 +193,7 @@ void Variable::set(int narg, char **arg) // 2 args + pad: num = N2, which = N1, data = single string } else if (strcmp(arg[1],"loop") == 0) { + if (narg < 3) utils::missing_cmd_args(FLERR, "variable loop", error); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = LOOP; @@ -200,7 +201,7 @@ void Variable::set(int narg, char **arg) if (narg == 3 || (narg == 4 && strcmp(arg[3],"pad") == 0)) { nfirst = 1; nlast = utils::inumeric(FLERR,arg[2],false,lmp); - if (nlast <= 0) error->all(FLERR,"Illegal variable command"); + if (nlast <= 0) error->all(FLERR, "Invalid variable loop argument: {}", nlast); if (narg == 4 && strcmp(arg[3],"pad") == 0) { pad[nvar] = fmt::format("{}",nlast).size(); } else pad[nvar] = 0; @@ -208,11 +209,11 @@ void Variable::set(int narg, char **arg) nfirst = utils::inumeric(FLERR,arg[2],false,lmp); nlast = utils::inumeric(FLERR,arg[3],false,lmp); if (nfirst > nlast || nlast < 0) - error->all(FLERR,"Illegal variable command"); + error->all(FLERR,"Illegal variable loop command: {} > {}", nfirst,nlast); if (narg == 5 && strcmp(arg[4],"pad") == 0) { pad[nvar] = fmt::format("{}",nlast).size(); } else pad[nvar] = 0; - } else error->all(FLERR,"Illegal variable command"); + } else error->all(FLERR,"Illegal variable loop command: too much arguments"); num[nvar] = nlast; which[nvar] = nfirst-1; data[nvar] = new char*[1]; @@ -223,7 +224,7 @@ void Variable::set(int narg, char **arg) // error check that num = # of worlds in universe } else if (strcmp(arg[1],"world") == 0) { - if (narg < 3) error->all(FLERR,"Illegal variable command"); + if (narg < 3) utils::missing_cmd_args(FLERR, "variable world", error); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = WORLD; @@ -244,7 +245,7 @@ void Variable::set(int narg, char **arg) } else if (strcmp(arg[1],"universe") == 0 || strcmp(arg[1],"uloop") == 0) { if (strcmp(arg[1],"universe") == 0) { - if (narg < 3) error->all(FLERR,"Illegal variable command"); + if (narg < 3) utils::missing_cmd_args(FLERR, "variable universe", error); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = UNIVERSE; @@ -253,8 +254,10 @@ void Variable::set(int narg, char **arg) data[nvar] = new char*[num[nvar]]; copy(num[nvar],&arg[2],data[nvar]); } else if (strcmp(arg[1],"uloop") == 0) { - if (narg < 3 || narg > 4 || (narg == 4 && strcmp(arg[3],"pad") != 0)) - error->all(FLERR,"Illegal variable command"); + if (narg < 3 || narg > 4) + error->all(FLERR,"Illegal variable command: expected 3 or 4 arguments but found {}", narg); + if (narg == 4 && strcmp(arg[3],"pad") != 0) + error->all(FLERR, "Invalid variable uloop argument: {}", arg[3]); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = ULOOP; @@ -292,7 +295,7 @@ void Variable::set(int narg, char **arg) // data = 1 value, string to eval } else if (strcmp(arg[1],"string") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); int maxcopy = strlen(arg[2]) + 1; int maxwork = maxcopy; @@ -326,7 +329,7 @@ void Variable::set(int narg, char **arg) // data = 1 value, string to eval } else if (strcmp(arg[1],"getenv") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); if (find(arg[0]) >= 0) { if (style[find(arg[0])] != GETENV) error->all(FLERR,"Cannot redefine variable as a different style"); @@ -346,7 +349,7 @@ void Variable::set(int narg, char **arg) // data = 1 value, string to eval } else if (strcmp(arg[1],"file") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = SCALARFILE; @@ -364,7 +367,7 @@ void Variable::set(int narg, char **arg) // data = nullptr } else if (strcmp(arg[1],"atomfile") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = ATOMFILE; @@ -384,7 +387,7 @@ void Variable::set(int narg, char **arg) // 3rd is filled on retrieval } else if (strcmp(arg[1],"format") == 0) { - if (narg != 4) error->all(FLERR,"Illegal variable command"); + if (narg != 4) error->all(FLERR,"Illegal variable command: expected 4 arguments but found {}", narg); if (find(arg[0]) >= 0) return; if (nvar == maxvar) grow(); style[nvar] = FORMAT; @@ -404,7 +407,7 @@ void Variable::set(int narg, char **arg) // data = 2 values, 1st is string to eval, 2nd is filled on retrieval } else if (strcmp(arg[1],"equal") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); int ivar = find(arg[0]); if (ivar >= 0) { if (style[ivar] != EQUAL) @@ -430,7 +433,7 @@ void Variable::set(int narg, char **arg) // data = 1 value, string to eval } else if (strcmp(arg[1],"atom") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); int ivar = find(arg[0]); if (ivar >= 0) { if (style[ivar] != ATOM) @@ -454,7 +457,7 @@ void Variable::set(int narg, char **arg) // data = 1 value, string to eval } else if (strcmp(arg[1],"vector") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); int ivar = find(arg[0]); if (ivar >= 0) { if (style[ivar] != VECTOR) @@ -478,7 +481,7 @@ void Variable::set(int narg, char **arg) // data = 2 values, 1st is Python func to invoke, 2nd is filled by invoke } else if (strcmp(arg[1],"python") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); if (!python->is_enabled()) error->all(FLERR,"LAMMPS is not built with Python embedded"); int ivar = find(arg[0]); @@ -507,7 +510,7 @@ void Variable::set(int narg, char **arg) // dvalue = numeric initialization via platform::walltime() } else if (strcmp(arg[1],"timer") == 0) { - if (narg != 2) error->all(FLERR,"Illegal variable command"); + if (narg != 2) error->all(FLERR,"Illegal variable command: expected 2 arguments but found {}", narg); int ivar = find(arg[0]); if (ivar >= 0) { if (style[ivar] != TIMER) @@ -531,7 +534,7 @@ void Variable::set(int narg, char **arg) // dvalue = numeric initialization from 2nd arg, reset by internal_set() } else if (strcmp(arg[1],"internal") == 0) { - if (narg != 3) error->all(FLERR,"Illegal variable command"); + if (narg != 3) error->all(FLERR,"Illegal variable command: expected 3 arguments but found {}", narg); int ivar = find(arg[0]); if (ivar >= 0) { if (style[ivar] != INTERNAL) @@ -551,7 +554,7 @@ void Variable::set(int narg, char **arg) // unrecognized variable style - } else error->all(FLERR,"Illegal variable command"); + } else error->all(FLERR,"Unknown variable keyword: {}", arg[1]); // set name of variable, if not replacing one flagged with replaceflag // name must be all alphanumeric chars or underscores From 60b00bfa8fb12437989e882f1d01d6561fac7084 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Aug 2022 05:48:07 -0400 Subject: [PATCH 8/8] update unit tests for variable command --- src/variable.cpp | 3 ++- unittest/commands/test_variables.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/variable.cpp b/src/variable.cpp index d6eec9eeb3..4117c41da6 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -170,7 +170,8 @@ void Variable::set(int narg, char **arg) // doesn't matter if variable no longer exists if (strcmp(arg[1],"delete") == 0) { - if (narg != 2) error->all(FLERR,"Illegal variable command: expected 2 argument but found {}", narg); + if (narg != 2) + error->all(FLERR,"Illegal variable delete command: expected 2 arguments but found {}", narg); if (find(arg[0]) >= 0) remove(find(arg[0])); return; diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index cf124eeafd..2b1beddd48 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -197,11 +197,11 @@ TEST_F(VariableTest, CreateDelete) ASSERT_EQ(variable->internalstyle(variable->find("ten")), 1); TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable");); - TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy index");); - TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy delete xxx");); - TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy loop -1");); - TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy loop 10 1");); - TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy xxxx");); + TEST_FAILURE(".*ERROR: Illegal variable index command.*", command("variable dummy index");); + TEST_FAILURE(".*ERROR: Illegal variable delete command: expected 2 arguments but found 3.*", command("variable dummy delete xxx");); + TEST_FAILURE(".*ERROR: Invalid variable loop argument: -1.*", command("variable dummy loop -1");); + TEST_FAILURE(".*ERROR: Illegal variable loop command.*", command("variable dummy loop 10 1");); + TEST_FAILURE(".*ERROR: Unknown variable keyword: xxx.*", command("variable dummy xxxx");); TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", command("variable two string xxx");); TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*",