Improve transformation coordinate expression checks
authorBerk Hess <hess@kth.se>
Mon, 4 Oct 2021 09:58:33 +0000 (11:58 +0200)
committerBerk Hess <hess@kth.se>
Mon, 4 Oct 2021 10:52:12 +0000 (12:52 +0200)
Change exceptions for transformation expression evaluation from
"internal bug" to "user input inconsistency", as these with throw
with incorrect or inconsistent user input.

Added explicit check for quotes, as that might confuse users.

src/gromacs/gmxpreprocess/readpull.cpp
src/gromacs/pulling/transformationcoordinate.cpp

index b8062ee54c86591c704374b527ebbe920af3b8d2..2524976cb583bf942e49fdc43b1e51d74ade2a99 100644 (file)
@@ -152,6 +152,12 @@ static void initTransformationPullCoord(t_pull_coord* pcrd, const pull_params_t&
                                   "'transformation'",
                                   coord_index_for_output)));
     }
+    else if (pcrd->expression[0] == '"' || pcrd->expression[0] == '\'')
+    {
+        GMX_THROW(gmx::InvalidInputError(gmx::formatString(
+                "pull-coord%d-expression should not start with double quote or a quote",
+                coord_index_for_output)));
+    }
     if (pcrd->dx == 0)
     {
         GMX_THROW(gmx::InvalidInputError(gmx::formatString(
index 5271e397d08074b0a6f14f9bf2b292da9eee140a..e3c1cea9e140d1413c38c0e50a2188efea08bedd 100644 (file)
@@ -65,7 +65,7 @@ double getTransformationPullCoordinateValue(pull_coord_work_t* coord)
 #if HAVE_MUPARSER
     catch (mu::Parser::exception_type& e)
     {
-        GMX_THROW(InternalError(
+        GMX_THROW(InconsistentInputError(
                 formatString("failed to evaluate expression for transformation pull-coord%d: %s\n",
                              transformationPullCoordinateIndex + 1,
                              e.GetMsg().c_str())));
@@ -73,7 +73,7 @@ double getTransformationPullCoordinateValue(pull_coord_work_t* coord)
 #endif
     catch (std::exception& e)
     {
-        GMX_THROW(InternalError(
+        GMX_THROW(InconsistentInputError(
                 formatString("failed to evaluate expression for transformation pull-coord%d.\n"
                              "Last variable pull-coord-index: %d.\n"
                              "Message:  %s\n",