Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix error handling.
authorBruno Donassolo <bruno.donassolo@inria.fr>
Fri, 2 Apr 2021 10:01:09 +0000 (12:01 +0200)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Fri, 2 Apr 2021 10:01:09 +0000 (12:01 +0200)
Raise std::invalid_argument exception instead of dying.

Thanks for the review ;)

include/simgrid/s4u/Host.hpp
include/simgrid/s4u/Link.hpp
include/simgrid/s4u/NetZone.hpp
src/s4u/s4u_Host.cpp
src/s4u/s4u_Link.cpp
src/s4u/s4u_Netzone.cpp

index 3fc3b0c..834944e 100644 (file)
@@ -119,7 +119,11 @@ public:
    * @param speed_per_state list of powers for this processor (default power is at index 0)
    */
   Host* set_pstate_speed(const std::vector<double>& speed_per_state);
-  /** @brief Set the CPU's speed (string version) */
+  /**
+   * @brief Set the CPU's speed (string version)
+   *
+   * @throw std::invalid_argument if speed format is incorrect.
+   */
   Host* set_pstate_speed(const std::vector<std::string>& speed_per_state);
 
   /** @brief Get the peak computing speed in flops/s at the current pstate, NOT taking the external load into account.
index 05808a1..8ee0cf9 100644 (file)
@@ -64,7 +64,11 @@ public:
    * @param value New latency value (in s)
    */
   Link* set_latency(double value);
-  /** @brief Set latency (string version) */
+  /**
+   * @brief Set latency (string version)
+   *
+   * @throw std::invalid_argument if latency format is incorrect.
+   */
   Link* set_latency(const std::string& value);
 
   /** @brief Describes how the link is shared between flows */
index 4d00516..1fc5dc8 100644 (file)
@@ -85,7 +85,11 @@ public:
    * @param speed_per_state Vector of CPU's speeds
    */
   s4u::Host* create_host(const std::string& name, const std::vector<double>& speed_per_pstate);
-  /** @brief Create a Host (string version) */
+  /**
+   * @brief Create a Host (string version)
+   *
+   * @throw std::invalid_argument if speed format is incorrect.
+   */
   s4u::Host* create_host(const std::string& name, const std::vector<std::string>& speed_per_pstate);
 
   /**
@@ -94,6 +98,7 @@ public:
    * @param name Link name
    * @param bandwidths Link's speed (vector for wifi links)
    * @param policy Link sharing policy
+   * @throw std::invalid_argument if bandwidth format is incorrect.
    */
   s4u::Link* create_link(const std::string& name, const std::vector<double>& bandwidths,
                          Link::SharingPolicy policy = Link::SharingPolicy::SHARED);
index fdaf2ca..08234c4 100644 (file)
@@ -280,7 +280,7 @@ std::vector<double> Host::convert_pstate_speed_vector(const std::vector<std::str
       double speed = xbt_parse_get_speed("", 0, speed_str.c_str(), nullptr, "");
       speed_list.push_back(speed);
     } catch (const simgrid::ParseError&) {
-      xbt_die("Host: Impossible to set_pstate_speed, invalid speed %s", speed_str.c_str());
+      throw std::invalid_argument(std::string("Invalid speed value: ") + speed_str);
     }
   }
   return speed_list;
index 7b195fb..011917a 100644 (file)
@@ -75,7 +75,8 @@ Link* Link::set_latency(const std::string& value)
   try {
     d_value = xbt_parse_get_time("", 0, value.c_str(), nullptr, "");
   } catch (const simgrid::ParseError&) {
-    xbt_die("Link: Impossible to latency, invalid value %s", value.c_str());
+    throw std::invalid_argument(std::string("Impossible to set latency for link: ") + get_name() +
+                                std::string(". Invalid value: ") + value);
   }
   return set_latency(d_value);
 }
index 57c83f3..2de7941 100644 (file)
@@ -148,7 +148,8 @@ s4u::Link* NetZone::create_link(const std::string& name, const std::vector<std::
       double speed = xbt_parse_get_bandwidth("", 0, speed_str.c_str(), nullptr, "");
       bw.push_back(speed);
     } catch (const simgrid::ParseError&) {
-      xbt_die("Link: Impossible to create_link, invalid bandwidth %s", speed_str.c_str());
+      throw std::invalid_argument(std::string("Impossible to create link: ") + name +
+                                  std::string(". Invalid bandwidth: ") + speed_str);
     }
   }
   return create_link(name, bw, policy);