LAMMPS WWW Site - LAMMPS Documentation - LAMMPS Mailing List Archives
Re: [lammps-users] Substitution for illegal variable error message
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lammps-users] Substitution for illegal variable error message


From: Axel Kohlmeyer <akohlmey@...24...>
Date: Mon, 6 Nov 2017 10:39:52 -0500



On Mon, Nov 6, 2017 at 10:19 AM, Noam Bernstein <noam.bernstein@...4479...> wrote:
Is there a chance that some information could be added to the “substitution for illegal variable” error message”?  From what I’ve found it says nothing about what variable or what input line, which makes it somewhat harder to debug than it needs to be.  Either of those would help.

​would something like this change help?

diff --git a/src/error.cpp b/src/error.cpp
index 0969507fc..9193314fc 100644
--- a/src/error.cpp
+++ b/src/error.cpp
@@ -152,9 +152,17 @@ void Error::all(const char *file, int line, const char *str)
 void Error::one(const char *file, int line, const char *str)
 {
   int me;
+  const char *lastcmd = (const char*)"(unknown)";
   MPI_Comm_rank(world,&me);
-  if (screen) fprintf(screen,"ERROR on proc %d: %s (%s:%d)\n",
-                      me,str,file,line);
+
+  if (input && input->line) lastcmd = input->line;
+  if (screen) fprintf(screen,"ERROR on proc %d: %s (%s:%d)\n"
+                      "Last command: %s\n",
+                      me,str,file,line,lastcmd);
+  if (logfile) fprintf(logfile,"ERROR on proc %d: %s (%s:%d)\n"
+                       "Last command: %s\n",
+                       me,str,file,line,lastcmd);
+
   if (universe->nworlds > 1)
     if (universe->uscreen)
       fprintf(universe->uscreen,"ERROR on proc %d: %s (%s:%d)\n",
diff --git a/src/input.cpp b/src/input.cpp
index 23b89d304..3d287771b 100644
--- a/src/input.cpp
+++ b/src/input.cpp
@@ -530,8 +530,11 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag)
         value = variable->retrieve(var);
       }
 
-      if (value == NULL) error->one(FLERR,"Substitution for illegal variable");
-
+      if (value == NULL) {
+        char str[128];
+        sprintf(str,"Substitution for illegal variable %s",var);
+        error->one(FLERR,str);
+      }
       // check if storage in str2 needs to be expanded
       // re-initialize ptr and ptr2 to the point beyond the variable.
 ​

 

                                                        thanks,
                                                        Noam


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
lammps-users mailing list
lammps-users@...6297....sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lammps-users



--
Dr. Axel Kohlmeyer  akohlmey@...24...  http://goo.gl/1wk0
College of Science & Technology, Temple University, Philadelphia PA, USA
International Centre for Theoretical Physics, Trieste. Italy.