From 6e1438e36d0b7e01709662dd33f89d5b6b63e3f5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Thu, 14 Apr 2022 12:40:13 +0200
Subject: [PATCH] Simplify error messages

Revert previous change when a boundary is not found. The "improved"
error message could be confusing...
---
 src/mesh/MeshCellZone.cpp           | 12 +-----------
 src/mesh/MeshFaceBoundary.cpp       | 13 +------------
 src/mesh/MeshFlatFaceBoundary.cpp   | 13 +------------
 src/mesh/MeshNodeBoundary.cpp       | 14 +++++++-------
 tests/test_MeshFaceBoundary.cpp     |  4 +---
 tests/test_MeshFlatFaceBoundary.cpp | 20 ++++++++++----------
 6 files changed, 21 insertions(+), 55 deletions(-)

diff --git a/src/mesh/MeshCellZone.cpp b/src/mesh/MeshCellZone.cpp
index 5b9128155..ac63998b6 100644
--- a/src/mesh/MeshCellZone.cpp
+++ b/src/mesh/MeshCellZone.cpp
@@ -23,17 +23,7 @@ getMeshCellZone(const Mesh<Connectivity<Dimension>>& mesh, const IZoneDescriptor
   }
 
   std::ostringstream ost;
-  ost << "cannot find cell set with name " << rang::fgB::red << zone_descriptor << rang::style::reset << '\n';
-  ost << "The mesh contains " << mesh.connectivity().template numberOfRefItemList<ItemType::cell>() << " cell sets: ";
-  for (size_t i_ref_cell_list = 0; i_ref_cell_list < mesh.connectivity().template numberOfRefItemList<ItemType::cell>();
-       ++i_ref_cell_list) {
-    const auto& ref_cell_list = mesh.connectivity().template refItemList<ItemType::cell>(i_ref_cell_list);
-    const RefId& ref          = ref_cell_list.refId();
-    if (i_ref_cell_list > 0) {
-      ost << ", ";
-    }
-    ost << rang::fgB::yellow << ref << rang::style::reset;
-  }
+  ost << "cannot find cell set with name \"" << rang::fgB::red << zone_descriptor << rang::style::reset << '\"';
 
   throw NormalError(ost.str());
 }
diff --git a/src/mesh/MeshFaceBoundary.cpp b/src/mesh/MeshFaceBoundary.cpp
index 5423ad639..f061ed646 100644
--- a/src/mesh/MeshFaceBoundary.cpp
+++ b/src/mesh/MeshFaceBoundary.cpp
@@ -36,18 +36,7 @@ getMeshFaceBoundary(const Mesh<Connectivity<Dimension>>& mesh, const IBoundaryDe
   }
 
   std::ostringstream ost;
-  ost << "cannot find face list with name " << rang::fgB::red << boundary_descriptor << rang::style::reset << '\n';
-  ost << "The mesh contains " << mesh.connectivity().template numberOfRefItemList<ItemType::face>()
-      << " referenced face lists: ";
-  for (size_t i_ref_face_list = 0; i_ref_face_list < mesh.connectivity().template numberOfRefItemList<ItemType::face>();
-       ++i_ref_face_list) {
-    const auto& ref_face_list = mesh.connectivity().template refItemList<ItemType::face>(i_ref_face_list);
-    const RefId& ref          = ref_face_list.refId();
-    if (i_ref_face_list > 0) {
-      ost << ", ";
-    }
-    ost << rang::fgB::yellow << ref << rang::style::reset;
-  }
+  ost << "cannot find face list with name " << rang::fgB::red << boundary_descriptor << rang::style::reset;
 
   throw NormalError(ost.str());
 }
diff --git a/src/mesh/MeshFlatFaceBoundary.cpp b/src/mesh/MeshFlatFaceBoundary.cpp
index 5759fe9e5..cb7740c67 100644
--- a/src/mesh/MeshFlatFaceBoundary.cpp
+++ b/src/mesh/MeshFlatFaceBoundary.cpp
@@ -20,18 +20,7 @@ getMeshFlatFaceBoundary(const Mesh<Connectivity<Dimension>>& mesh, const IBounda
   }
 
   std::ostringstream ost;
-  ost << "cannot find face list with name " << rang::fgB::red << boundary_descriptor << rang::style::reset << '\n';
-  ost << "The mesh contains " << mesh.connectivity().template numberOfRefItemList<ItemType::face>()
-      << " referenced face lists: ";
-  for (size_t i_ref_face_list = 0; i_ref_face_list < mesh.connectivity().template numberOfRefItemList<ItemType::face>();
-       ++i_ref_face_list) {
-    const auto& ref_face_list = mesh.connectivity().template refItemList<ItemType::face>(i_ref_face_list);
-    const RefId& ref          = ref_face_list.refId();
-    if (i_ref_face_list > 0) {
-      ost << ", ";
-    }
-    ost << rang::fgB::yellow << ref << rang::style::reset;
-  }
+  ost << "cannot find face list with name \"" << rang::fgB::red << boundary_descriptor << rang::style::reset << "\"";
 
   throw NormalError(ost.str());
 }
diff --git a/src/mesh/MeshNodeBoundary.cpp b/src/mesh/MeshNodeBoundary.cpp
index 6c18637a0..b992fc77b 100644
--- a/src/mesh/MeshNodeBoundary.cpp
+++ b/src/mesh/MeshNodeBoundary.cpp
@@ -176,8 +176,8 @@ MeshNodeBoundary<Dimension>::MeshNodeBoundary(const Mesh<Connectivity<Dimension>
   const Array<const FaceId>& face_list = ref_face_list.list();
   if (not ref_face_list.isBoundary()) {
     std::ostringstream ost;
-    ost << "invalid boundary " << rang::fgB::yellow << this->m_boundary_name << rang::style::reset
-        << ": inner faces cannot be used to define mesh boundaries";
+    ost << "invalid boundary \"" << rang::fgB::yellow << this->m_boundary_name << rang::style::reset
+        << "\": inner faces cannot be used to define mesh boundaries";
     throw NormalError(ost.str());
   }
 
@@ -224,8 +224,8 @@ MeshNodeBoundary<Dimension>::MeshNodeBoundary(const Mesh<Connectivity<Dimension>
   const Array<const EdgeId>& edge_list = ref_edge_list.list();
   if (not ref_edge_list.isBoundary()) {
     std::ostringstream ost;
-    ost << "invalid boundary " << rang::fgB::yellow << this->m_boundary_name << rang::style::reset
-        << ": inner edges cannot be used to define mesh boundaries";
+    ost << "invalid boundary \"" << rang::fgB::yellow << this->m_boundary_name << rang::style::reset
+        << "\": inner edges cannot be used to define mesh boundaries";
     throw NormalError(ost.str());
   }
 
@@ -269,8 +269,8 @@ MeshNodeBoundary<Dimension>::MeshNodeBoundary(const Mesh<Connectivity<Dimension>
 {
   if (not ref_node_list.isBoundary()) {
     std::ostringstream ost;
-    ost << "invalid boundary " << rang::fgB::yellow << this->m_boundary_name << rang::style::reset
-        << ": inner nodes cannot be used to define mesh boundaries";
+    ost << "invalid boundary \"" << rang::fgB::yellow << this->m_boundary_name << rang::style::reset
+        << "\": inner nodes cannot be used to define mesh boundaries";
     throw NormalError(ost.str());
   }
 }
@@ -317,7 +317,7 @@ getMeshNodeBoundary(const Mesh<Connectivity<Dimension>>& mesh, const IBoundaryDe
   }
 
   std::ostringstream ost;
-  ost << "cannot find surface with name " << rang::fgB::red << boundary_descriptor << rang::style::reset;
+  ost << "cannot find node list with name " << rang::fgB::red << boundary_descriptor << rang::style::reset;
 
   throw NormalError(ost.str());
 }
diff --git a/tests/test_MeshFaceBoundary.cpp b/tests/test_MeshFaceBoundary.cpp
index 3ab99dcd3..472427aaf 100644
--- a/tests/test_MeshFaceBoundary.cpp
+++ b/tests/test_MeshFaceBoundary.cpp
@@ -275,9 +275,7 @@ TEST_CASE("MeshFaceBoundary", "[mesh]")
       NamedBoundaryDescriptor named_boundary_descriptor("invalid_boundary");
 
       REQUIRE_THROWS_WITH(getMeshFaceBoundary(mesh, named_boundary_descriptor),
-                          "error: cannot find face list with name \"invalid_boundary\"\nThe mesh contains 8 referenced "
-                          "face lists: XMIN(22), XMAX(23), ZMAX(24), ZMIN(25), YMAX(26), YMIN(27), INTERFACE1(55), "
-                          "INTERFACE2(56)");
+                          "error: cannot find face list with name \"invalid_boundary\"");
     }
 
     SECTION("surface is inside")
diff --git a/tests/test_MeshFlatFaceBoundary.cpp b/tests/test_MeshFlatFaceBoundary.cpp
index ffd81828e..446c9b478 100644
--- a/tests/test_MeshFlatFaceBoundary.cpp
+++ b/tests/test_MeshFlatFaceBoundary.cpp
@@ -976,7 +976,7 @@ TEST_CASE("MeshFlatFaceBoundary", "[mesh]")
           {
             NumberedBoundaryDescriptor numbered_boundary_descriptor(3);
             REQUIRE_THROWS_WITH(getMeshFlatFaceBoundary(mesh, numbered_boundary_descriptor),
-                                "error: invalid boundary YMAX: boundary is not flat!");
+                                "error: invalid boundary \"YMAX\": boundary is not flat!");
           }
         }
 
@@ -1009,7 +1009,7 @@ TEST_CASE("MeshFlatFaceBoundary", "[mesh]")
           {
             NamedBoundaryDescriptor named_boundary_descriptor("YMAX");
             REQUIRE_THROWS_WITH(getMeshFlatFaceBoundary(mesh, named_boundary_descriptor),
-                                "error: invalid boundary YMAX: boundary is not flat!");
+                                "error: invalid boundary \"YMAX\": boundary is not flat!");
           }
         }
       }
@@ -1084,13 +1084,13 @@ TEST_CASE("MeshFlatFaceBoundary", "[mesh]")
           {
             NumberedBoundaryDescriptor numbered_boundary_descriptor(3);
             REQUIRE_THROWS_WITH(getMeshFlatFaceBoundary(mesh, numbered_boundary_descriptor),
-                                "error: invalid boundary YMAX: boundary is not flat!");
+                                "error: invalid boundary \"YMAX\": boundary is not flat!");
           }
 
           {
             NumberedBoundaryDescriptor numbered_boundary_descriptor(5);
             REQUIRE_THROWS_WITH(getMeshFlatFaceBoundary(mesh, numbered_boundary_descriptor),
-                                "error: invalid boundary ZMAX: boundary is not flat!");
+                                "error: invalid boundary \"ZMAX\": boundary is not flat!");
           }
         }
 
@@ -1125,13 +1125,13 @@ TEST_CASE("MeshFlatFaceBoundary", "[mesh]")
           {
             NamedBoundaryDescriptor named_boundary_descriptor("YMAX");
             REQUIRE_THROWS_WITH(getMeshFlatFaceBoundary(mesh, named_boundary_descriptor),
-                                "error: invalid boundary YMAX: boundary is not flat!");
+                                "error: invalid boundary \"YMAX\": boundary is not flat!");
           }
 
           {
             NamedBoundaryDescriptor named_boundary_descriptor("ZMAX");
             REQUIRE_THROWS_WITH(getMeshFlatFaceBoundary(mesh, named_boundary_descriptor),
-                                "error: invalid boundary ZMAX: boundary is not flat!");
+                                "error: invalid boundary \"ZMAX\": boundary is not flat!");
           }
         }
       }
@@ -1195,13 +1195,13 @@ TEST_CASE("MeshFlatFaceBoundary", "[mesh]")
           {
             NumberedBoundaryDescriptor numbered_boundary_descriptor(24);
             REQUIRE_THROWS_WITH(getMeshFlatFaceBoundary(mesh, numbered_boundary_descriptor),
-                                "error: invalid boundary ZMAX: boundary is not flat!");
+                                "error: invalid boundary \"ZMAX\": boundary is not flat!");
           }
 
           {
             NumberedBoundaryDescriptor numbered_boundary_descriptor(26);
             REQUIRE_THROWS_WITH(getMeshFlatFaceBoundary(mesh, numbered_boundary_descriptor),
-                                "error: invalid boundary YMAX: boundary is not flat!");
+                                "error: invalid boundary \"YMAX\": boundary is not flat!");
           }
         }
 
@@ -1236,13 +1236,13 @@ TEST_CASE("MeshFlatFaceBoundary", "[mesh]")
           {
             NamedBoundaryDescriptor named_boundary_descriptor("YMAX");
             REQUIRE_THROWS_WITH(getMeshFlatFaceBoundary(mesh, named_boundary_descriptor),
-                                "error: invalid boundary YMAX: boundary is not flat!");
+                                "error: invalid boundary \"YMAX\": boundary is not flat!");
           }
 
           {
             NamedBoundaryDescriptor named_boundary_descriptor("ZMAX");
             REQUIRE_THROWS_WITH(getMeshFlatFaceBoundary(mesh, named_boundary_descriptor),
-                                "error: invalid boundary ZMAX: boundary is not flat!");
+                                "error: invalid boundary \"ZMAX\": boundary is not flat!");
           }
         }
       }
-- 
GitLab