From a34df2e17d620fc5db50321371f1a9e77e38cb65 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@uliege.be>
Date: Sat, 24 Oct 2020 10:58:38 +0200
Subject: [PATCH] rework some error/warning messages

---
 Mesh/BDS.cpp                          |  2 +-
 Mesh/BackgroundMeshTools.cpp          |  2 +-
 Mesh/Field.cpp                        | 14 +++++++-------
 Mesh/Generator.cpp                    | 16 ++++++++--------
 Mesh/delaunay3d.cpp                   |  6 +++---
 Mesh/meshGEdge.cpp                    |  2 +-
 Mesh/meshGFaceBamg.cpp                |  7 +++----
 Mesh/meshGFaceExtruded.cpp            | 15 ++++-----------
 Mesh/meshGRegionBoundaryLayer.cpp     | 17 ++++++++---------
 Mesh/meshGRegionBoundaryRecovery.cpp  |  2 +-
 Mesh/meshGRegionDelaunayInsertion.cpp |  6 +++---
 Mesh/meshGRegionExtruded.cpp          |  4 ++--
 Mesh/meshGRegionLocalMeshMod.cpp      |  3 +--
 Mesh/meshMetric.cpp                   |  8 ++++----
 Mesh/meshPartition.cpp                |  2 +-
 15 files changed, 48 insertions(+), 58 deletions(-)

diff --git a/Mesh/BDS.cpp b/Mesh/BDS.cpp
index 4b6688f166..0a69eedc4b 100644
--- a/Mesh/BDS.cpp
+++ b/Mesh/BDS.cpp
@@ -50,7 +50,7 @@ void outputScalarField(std::vector<BDS_Face *> &t, const char *iii, int param,
   if(gf && 0) {
     FILE *view_c = Fopen("param_mesh_as_it_is_in_3D.pos", "w");
     if(!view_c) {
-      Msg::Error("Could not open file param_mesh_as_it_is_in_3D.pos");
+      Msg::Error("Could not open file 'param_mesh_as_it_is_in_3D.pos'");
       return;
     }
     fprintf(view_c, "View \"paramC\"{\n");
diff --git a/Mesh/BackgroundMeshTools.cpp b/Mesh/BackgroundMeshTools.cpp
index 77861aefcd..e40ed26cf7 100644
--- a/Mesh/BackgroundMeshTools.cpp
+++ b/Mesh/BackgroundMeshTools.cpp
@@ -120,7 +120,7 @@ SMetric3 LC_MVertex_CURV_ANISO(GEntity *ge, double U, double V)
   case 2:
     return metric_based_on_surface_curvature((const GFace *)ge, U, V, iso_surf);
   }
-  Msg::Error("Curvature control impossible to compute for a volume!");
+  Msg::Error("Curvature control impossible to compute for a volume");
   return SMetric3();
 }
 
diff --git a/Mesh/Field.cpp b/Mesh/Field.cpp
index a3e9756de5..e3219b7f40 100644
--- a/Mesh/Field.cpp
+++ b/Mesh/Field.cpp
@@ -63,7 +63,7 @@ FieldOption *Field::getOption(const std::string &optionName)
 {
   std::map<std::string, FieldOption *>::iterator it = options.find(optionName);
   if(it == options.end()) {
-    Msg::Error("field option :%s does not exist", optionName.c_str());
+    Msg::Error("Field option '%s' does not exist", optionName.c_str());
     return NULL;
   }
   return it->second;
@@ -219,7 +219,7 @@ public:
         input.close();
       } catch(...) {
         _errorStatus = true;
-        Msg::Error("Field %i : error reading file %s", this->id,
+        Msg::Error("Field %i: error reading file '%s'", this->id,
                    _fileName.c_str());
       }
       updateNeeded = false;
@@ -699,7 +699,7 @@ public:
            _delta;
       return sqrt(gx * gx + gy * gy + gz * gz);
     default:
-      Msg::Error("Field %i : Unknown kind (%i) of gradient", this->id, _kind);
+      Msg::Error("Field %i: unknown kind (%i) of gradient", this->id, _kind);
       return MAX_LC;
     }
   }
@@ -1045,7 +1045,7 @@ public:
     {
       if(updateNeeded) {
         if(!_expr.set_function(_f))
-          Msg::Error("Field %i: Invalid matheval expression \"%s\"", this->id,
+          Msg::Error("Field %i: invalid matheval expression \"%s\"", this->id,
                      _f.c_str());
         updateNeeded = false;
       }
@@ -1099,7 +1099,7 @@ public:
       if(updateNeeded) {
         for(int i = 0; i < 6; i++) {
           if(!_expr.set_function(i, _f[i]))
-            Msg::Error("Field %i: Invalid matheval expression \"%s\"", this->id,
+            Msg::Error("Field %i: invalid matheval expression \"%s\"", this->id,
                        _f[i].c_str());
         }
         updateNeeded = false;
@@ -1117,7 +1117,7 @@ public:
       if(updateNeeded) {
         for(int i = 0; i < 6; i++) {
           if(!_expr.set_function(i, _f[i]))
-            Msg::Error("Field %i: Invalid matheval expression \"%s\"", this->id,
+            Msg::Error("Field %i: invalid matheval expression \"%s\"", this->id,
                        _f[i].c_str());
         }
         updateNeeded = false;
@@ -1402,7 +1402,7 @@ public:
     if(updateNeeded) {
       for(int i = 0; i < 3; i++) {
         if(!_expr[i].set_function(_f[i]))
-          Msg::Error("Field %i : Invalid matheval expression \"%s\"", this->id,
+          Msg::Error("Field %i: invalid matheval expression \"%s\"", this->id,
                      _f[i].c_str());
       }
       updateNeeded = false;
diff --git a/Mesh/Generator.cpp b/Mesh/Generator.cpp
index 392e2160ce..3ae75138ef 100644
--- a/Mesh/Generator.cpp
+++ b/Mesh/Generator.cpp
@@ -101,10 +101,10 @@ public:
     if(edges.size()) {
       char name[256];
       sprintf(name, "missingEdgesOnRegion%d.pos", gr->tag());
-      Msg::Error("Region %d : %d mesh edges that should be embedded are "
+      Msg::Warning("Region %d : %d mesh edges that should be embedded are "
                  "missing in the final mesh",
                  gr->tag(), (int)edges.size());
-      Msg::Error("Saving the missing edges in file %s", name);
+      Msg::Info("Saving the missing edges in file %s", name);
       FILE *f = fopen(name, "w");
       fprintf(f, "View \" \" {\n");
       for(std::map<MEdge, GEdge *, MEdgeLessThan>::iterator it = edges.begin();
@@ -121,10 +121,10 @@ public:
     if(faces.size()) {
       char name[256];
       sprintf(name, "missingFacesOnRegion%d.pos", gr->tag());
-      Msg::Error("Volume %d : %d mesh faces that should be embedded are "
+      Msg::Warning("Volume %d : %d mesh faces that should be embedded are "
                  "missing in the final mesh",
                  gr->tag(), (int)faces.size());
-      Msg::Error("Saving the missing faces in file %s", name);
+      Msg::Info("Saving the missing faces in file %s", name);
       FILE *f = fopen(name, "w");
       fprintf(f, "View \" \" {\n");
       for(std::map<MFace, GFace *, MFaceLessThan>::iterator it = faces.begin();
@@ -370,7 +370,7 @@ static void Mesh1D(GModel *m)
 
   while(1) {
     if(CTX::instance()->abortOnError && Msg::GetErrorCount()) {
-      Msg::Error("Aborted 1D meshing");
+      Msg::Warning("Aborted 1D meshing");
       break;
     }
 
@@ -521,7 +521,7 @@ static void Mesh2D(GModel *m)
 
     while(1) {
       if(CTX::instance()->abortOnError && Msg::GetErrorCount()) {
-        Msg::Error("Aborted 2D meshing");
+        Msg::Warning("Aborted 2D meshing");
         break;
       }
 
@@ -872,7 +872,7 @@ static void Mesh3D(GModel *m)
 
   for(std::size_t i = 0; i < connected.size(); i++) {
     if(CTX::instance()->abortOnError && Msg::GetErrorCount()) {
-      Msg::Error("Aborted 3D meshing");
+      Msg::Warning("Aborted 3D meshing");
       break;
     }
 
@@ -967,7 +967,7 @@ static void Mesh3D(GModel *m)
   }
   if(emptyRegionFound) {
     debugInfo << std::endl;
-    Msg::Error(debugInfo.str().c_str());
+    Msg::Warning(debugInfo.str().c_str());
   }
 
   Msg::SetNumThreads(prevNumThreads);
diff --git a/Mesh/delaunay3d.cpp b/Mesh/delaunay3d.cpp
index f5384d9292..2bc092692f 100644
--- a/Mesh/delaunay3d.cpp
+++ b/Mesh/delaunay3d.cpp
@@ -877,7 +877,7 @@ static Tet *walk(Tet *t, Vert *v, int maxx, double &totSearch, int thread)
       investigatedTets.insert(t);
     }
     else if(tets.empty()) {
-      Msg::Error("Jump-and-Walk Failed (No neighbor)");
+      Msg::Error("Jump-and-walk failed (no neighbor)");
       return 0;
     }
     else {
@@ -885,7 +885,7 @@ static Tet *walk(Tet *t, Vert *v, int maxx, double &totSearch, int thread)
       tets.pop();
     }
   }
-  Msg::Error("Jump-and-Walk Failed (No neighbor)");
+  Msg::Error("Jump-and-walk failed (no neighbor)");
   return 0;
 }
 
@@ -1140,7 +1140,7 @@ void delaunayTrgl(const std::size_t numThreads,
               else if(neigh->getFace(3) == bndK[i].f)
                 neigh->T[3] = t;
               else {
-                Msg::Error("Datastructure Broken in Triangulation");
+                Msg::Error("Datastructure broken in triangulation");
                 break;
               }
             }
diff --git a/Mesh/meshGEdge.cpp b/Mesh/meshGEdge.cpp
index fe22ced2fa..8a00035305 100644
--- a/Mesh/meshGEdge.cpp
+++ b/Mesh/meshGEdge.cpp
@@ -393,7 +393,7 @@ static void filterPoints(GEdge *ge, int nMinimumPoints)
   for(std::size_t i = 0; i < ge->mesh_vertices.size(); i++) {
     MEdgeVertex *v = dynamic_cast<MEdgeVertex *>(ge->mesh_vertices[i]);
     if(!v) {
-      Msg::Error("in 1D mesh filterPoints");
+      Msg::Error("Node not classified on curve in 1D mesh filtering");
       return;
     }
     double d = distance(v, v0);
diff --git a/Mesh/meshGFaceBamg.cpp b/Mesh/meshGFaceBamg.cpp
index a4ec34d1aa..3132e131c4 100644
--- a/Mesh/meshGFaceBamg.cpp
+++ b/Mesh/meshGFaceBamg.cpp
@@ -180,10 +180,10 @@ void meshGFaceBamg(GFace *gf)
 
     try {
       refinedBamgMesh = Bamg(bamgMesh, args, mm11, mm12, mm22, false);
-      Msg::Info("bamg succeeded %d vertices %d triangles", refinedBamgMesh->nv,
+      Msg::Info("BAMG succeeded %d vertices %d triangles", refinedBamgMesh->nv,
                 refinedBamgMesh->nt);
     } catch(...) {
-      Msg::Error("bamg failed");
+      Msg::Error("BAMG failed");
       return;
     }
     delete[] mm11;
@@ -248,8 +248,7 @@ void meshGFaceBamg(GFace *gf)
 
 void meshGFaceBamg(GFace *gf)
 {
-  Msg::Error("This version of Gmsh is not compiled with Bidimensional "
-             "Anisotropic Mesh Generator (BAMG) support");
+  Msg::Error("This version of Gmsh is not compiled with BAMG support");
 }
 
 #endif
diff --git a/Mesh/meshGFaceExtruded.cpp b/Mesh/meshGFaceExtruded.cpp
index f6e46213d9..408a9775ac 100644
--- a/Mesh/meshGFaceExtruded.cpp
+++ b/Mesh/meshGFaceExtruded.cpp
@@ -40,7 +40,7 @@ createQuaTri(std::vector<MVertex *> &v, GFace *to,
   else if(v[0] == v[2] || v[2] == v[3])
     addTriangle(v[0], v[1], v[3], to);
   else if(v[0] == v[3] || v[1] == v[2])
-    Msg::Error("Uncoherent extruded quadrangle in surface %d", to->tag());
+    Msg::Error("Incoherent extruded quadrangle in surface %d", to->tag());
   else {
     // Trevor Strickler added the tri_quad_flag stuff here.
     if((ep->mesh.Recombine && tri_quad_flag != 2) || tri_quad_flag == 1) {
@@ -137,10 +137,7 @@ extrudeMesh(GEdge *from, GFace *to, MVertexRTree &pos,
   bool quadToTri_valid =
     IsValidQuadToTriLateral(to, &tri_quad_flag, &detectQuadToTriLateral);
   if(detectQuadToTriLateral && !quadToTri_valid)
-    Msg::Error(
-      "In MeshGFaceExtrudedSurface::extrudeMesh(), Mesh of QuadToTri Lateral "
-      "surface %d likely has errors.",
-      to->tag());
+    Msg::Error("Mesh of QuadToTri lateral surface %d likely has errors", to->tag());
 #endif
 
   // create elements (note that it would be faster to access the *interior*
@@ -221,9 +218,7 @@ static void copyMesh(GFace *from, GFace *to, MVertexRTree &pos)
   bool is_toroidal = quadToTri_valid >= 2 ? true : false;
   bool is_noaddverts = quadToTri_valid == 3 ? true : false;
   if(detectQuadToTriTop && !quadToTri_valid && !is_toroidal) {
-    Msg::Error("In MeshGFaceExtrudedSurface::copyMesh(), Mesh of QuadToTri top "
-               "surface %d likely has errors.",
-               to->tag());
+    Msg::Error("Mesh of QuadToTri top surface %d likely has errors", to->tag());
   }
 
   // if this is toroidal No New Vertices QuadToTri, then replace the root
@@ -266,9 +261,7 @@ static void copyMesh(GFace *from, GFace *to, MVertexRTree &pos)
   // toroidal extrusion, mesh the top surface accordingly
   if(detectQuadToTriTop && !is_toroidal) {
     if(!MeshQuadToTriTopSurface(from, to, pos))
-      Msg::Error("In MeshExtrudedSurface()::copyMesh(), mesh of QuadToTri top "
-                 "surface %d failed.",
-                 to->tag());
+      Msg::Error("Mesh of QuadToTri top surface %d failed", to->tag());
     return;
   }
 #endif
diff --git a/Mesh/meshGRegionBoundaryLayer.cpp b/Mesh/meshGRegionBoundaryLayer.cpp
index 64690cf324..01da0df796 100644
--- a/Mesh/meshGRegionBoundaryLayer.cpp
+++ b/Mesh/meshGRegionBoundaryLayer.cpp
@@ -246,7 +246,7 @@ public:
           for(int k = 0; k < 2; k++) {
             MVertex *v = edges[i]->lines[j]->getVertex(k);
             std::set<blyr_mvertex>::iterator it = _vertices.find(v);
-            if(it == _vertices.end()) Msg::Error("error in blyr_manager");
+            if(it == _vertices.end()) Msg::Error("Unknow node in boundary layer");
             it->add_line(edges[i]->lines[j], edges[i]);
           }
         }
@@ -264,13 +264,13 @@ public:
           t_normals.find(t->getFace(0));
         SVector3 n;
         if(it == t_normals.end())
-          Msg::Error("BLYR ERROR");
+          Msg::Error("Unknown face in boundary layer");
         else
           n = it->second;
         for(int k = 0; k < 3; k++) {
           MVertex *v = t->getVertex(k);
           std::set<blyr_mvertex>::iterator it = _vertices.find(v);
-          if(it == _vertices.end()) Msg::Error("error in blyr_manager");
+          if(it == _vertices.end()) Msg::Error("Unknown node in boundary layer");
           it->add_triangle(t, n, bls[i]);
         }
       }
@@ -282,7 +282,7 @@ public:
     for(size_t i = 0; i < _ridges.size(); i++) {
       if(_ridges[i]._ge == ge) return &_ridges[i];
     }
-    Msg::Error("unknown ridge %d", ge->tag());
+    Msg::Error("Unknown ridge %d", ge->tag());
     return NULL;
   }
 
@@ -727,7 +727,7 @@ public:
             }
           }
           if(!gf)
-            Msg::Error("topological error in 3D Boundary Layer generation");
+            Msg::Error("Topological error in 3D boundary layer generation");
           GPoint gp = gf->closestPoint(p, initialGuess);
           printf("adding a point %g %g %g in face %d\n",
                  n.x(), n.y(), n.z(), gf->tag());
@@ -879,9 +879,8 @@ public:
           // ALREADY DONE (see function above)
         }
         else {
-          Msg::Error("corner with %d internal ridges and %d external ridges "
-                     "should be coded",
-                     nINTERNAL, nEXTERNAL);
+          Msg::Error("Corner with %d internal ridges and %d external ridges "
+                     "should be coded", nINTERNAL, nEXTERNAL);
           printf("EXTERNALS :");
           for(size_t i = 0; i < _externals.size(); i++)
             printf("%d ", _externals[i]->_ge->tag());
@@ -954,7 +953,7 @@ public:
             t = bounds.high() - thk / tgt.norm();
           }
           else
-            Msg::Error("topological error in boundary layer");
+            Msg::Error("Topological error in boundary layer");
           GPoint gp = ge->point(t);
           MEdgeVertex *mev = new MEdgeVertex(gp.x(), gp.y(), gp.z(), ge, t);
           ge->mesh_vertices.push_back(mev);
diff --git a/Mesh/meshGRegionBoundaryRecovery.cpp b/Mesh/meshGRegionBoundaryRecovery.cpp
index 926ff73f1b..76d02f4b23 100644
--- a/Mesh/meshGRegionBoundaryRecovery.cpp
+++ b/Mesh/meshGRegionBoundaryRecovery.cpp
@@ -1149,7 +1149,7 @@ namespace tetgenBR {
     }
     outfile = fopen(mefilename, "w");
     if(outfile == (FILE *)NULL) {
-      printf("File I/O Error:  Cannot create file %s.\n", mefilename);
+      Msg::Error("Could not open file '%s'", mefilename);
       return;
     }
 
diff --git a/Mesh/meshGRegionDelaunayInsertion.cpp b/Mesh/meshGRegionDelaunayInsertion.cpp
index 36b1d49fe0..036b18082d 100644
--- a/Mesh/meshGRegionDelaunayInsertion.cpp
+++ b/Mesh/meshGRegionDelaunayInsertion.cpp
@@ -69,7 +69,7 @@ static void testIfBoundaryIsRecovered(GRegion *gr)
     Msg::Info("All edges and faces are present in the initial mesh");
   }
   else {
-    Msg::Error("All edges and faces are NOT present in the initial mesh");
+    Msg::Error("All edges and faces are not present in the initial mesh");
   }
 }
 
@@ -666,7 +666,7 @@ void non_recursive_classify(MTet4 *t, std::list<MTet4 *> &theRegion,
     t = _stackounette.top();
     _stackounette.pop();
     if(!t) {
-      Msg::Error("A tetrahedron is not connected to a boundary face");
+      Msg::Warning("A tetrahedron is not connected to a boundary face");
       touchesOutsideBox = true;
     }
     else if(!t->onWhat()) {
@@ -1396,7 +1396,7 @@ void insertVerticesInRegion(GRegion *gr, int maxIter, double worstTetRadiusTarge
   while(1) {
     if(maxIter > 0 && ITER >= maxIter) break;
     if(allTets.empty()) {
-      Msg::Error("No tetrahedra in region %d", gr->tag());
+      Msg::Warning("No tetrahedra in region %d", gr->tag());
       break;
     }
 
diff --git a/Mesh/meshGRegionExtruded.cpp b/Mesh/meshGRegionExtruded.cpp
index cf45d5c511..821d64e601 100644
--- a/Mesh/meshGRegionExtruded.cpp
+++ b/Mesh/meshGRegionExtruded.cpp
@@ -537,8 +537,8 @@ int SubdivideExtrudedMesh(GModel *m)
           break;
         }
         else{
-          Msg::Error("Unable to subdivide extruded mesh: change surface mesh or");
-          Msg::Error("recombine extrusion instead");
+          Msg::Error("Unable to subdivide extruded mesh: change surface mesh or "
+                     "recombine extrusion instead");
           return -1;
         }
       }
diff --git a/Mesh/meshGRegionLocalMeshMod.cpp b/Mesh/meshGRegionLocalMeshMod.cpp
index 433b39b04c..a8bd1f761c 100644
--- a/Mesh/meshGRegionLocalMeshMod.cpp
+++ b/Mesh/meshGRegionLocalMeshMod.cpp
@@ -486,9 +486,8 @@ bool faceSwap(std::vector<MTet4 *> &newTets, MTet4 *t1, int iLocalFace,
 
 void buildVertexCavity_recur(MTet4 *t, MVertex *v, std::vector<MTet4 *> &cavity)
 {
-  // if (recur > 20)printf("oufti %d\n",recur);
   if(t->isDeleted()) {
-    Msg::Error("a deleted triangle is a neighbor of a non deleted triangle");
+    Msg::Error("A deleted triangle is a neighbor of a non deleted triangle");
     return;
   }
   int iV = -1;
diff --git a/Mesh/meshMetric.cpp b/Mesh/meshMetric.cpp
index 577dc7a9d8..cd907fc353 100644
--- a/Mesh/meshMetric.cpp
+++ b/Mesh/meshMetric.cpp
@@ -796,8 +796,8 @@ double meshMetric::operator()(double x, double y, double z, GEntity *ge)
 {
   if(needMetricUpdate) updateMetrics();
   if(!setOfMetrics.size()) {
-    std::cout << "meshMetric::operator() : No metric defined ! " << std::endl;
-    throw;
+    Msg::Error("No metric defined");
+    return 0.;
   }
   SPoint3 xyz(x, y, z), uvw;
   double initialTol = MElement::getTolerance();
@@ -836,8 +836,8 @@ void meshMetric::operator()(double x, double y, double z, SMetric3 &metr,
     updateMetrics();
   }
   if(!setOfMetrics.size()) {
-    std::cout << "meshMetric::operator() : No metric defined ! " << std::endl;
-    throw;
+    Msg::Error("No metric defined");
+    return;
   }
   metr = SMetric3(1.e-22);
 
diff --git a/Mesh/meshPartition.cpp b/Mesh/meshPartition.cpp
index bc857437f3..79541e45e7 100644
--- a/Mesh/meshPartition.cpp
+++ b/Mesh/meshPartition.cpp
@@ -2569,7 +2569,7 @@ int PartitionUsingThisSplit(GModel *model, std::size_t npart,
     elmToPartition[elmToPart[i].first] = elmToPart[i].second;
 
   if(elmToPartition.size() != graph.ne()) {
-    Msg::Error("All elements are not partitioned.");
+    Msg::Error("All elements are not partitioned");
     return 1;
   }
 
-- 
GitLab