Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Nice error message when creating a process on non-existing host
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 7 Feb 2016 13:49:01 +0000 (14:49 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 7 Feb 2016 13:52:02 +0000 (14:52 +0100)
include/xbt/strbuff.h
src/surf/sg_platf.cpp

index 79b2658..d76decc 100644 (file)
@@ -15,6 +15,8 @@
 #include "xbt/str.h"
 #include "xbt/dict.h"
 
+SG_BEGIN_DECL()
+
 /**
  ** Buffer code
  **/
@@ -35,4 +37,5 @@ XBT_PUBLIC(void) xbt_strbuff_trim(xbt_strbuff_t b);
 XBT_PUBLIC(void) xbt_strbuff_varsubst(xbt_strbuff_t b,
                                       xbt_dict_t patterns);
 
+SG_END_DECL()
 #endif
index e2968b1..f734c0b 100644 (file)
@@ -271,8 +271,27 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process)
     xbt_die("Cannot create process without SIMIX.");
 
   sg_host_t host = sg_host_by_name(process->host);
-  if (!host)
-    THROWF(arg_error, 0, "Host '%s' unknown", process->host);
+  if (!host) {
+    // The requested host does not exist. Do a nice message to the user
+    char *tmp = bprintf("Cannot create process '%s': host '%s' does not exist\nExisting hosts: '",process->function, process->host);
+    xbt_strbuff_t msg = xbt_strbuff_new_from(tmp);
+    free(tmp);
+    xbt_dynar_t all_hosts = xbt_dynar_sort_strings(sg_hosts_as_dynar());
+    simgrid::s4u::Host* host;
+    unsigned int cursor;
+    xbt_dynar_foreach(all_hosts,cursor, host) {
+      xbt_strbuff_append(msg,host->name().c_str());
+      xbt_strbuff_append(msg,"', '");
+      if (msg->used > 1024) {
+        msg->data[msg->used-3]='\0';
+        msg->used -= 3;
+
+        xbt_strbuff_append(msg," ...(list truncated)......");// That will be shortened by 3 chars when existing the loop
+      }
+    }
+    msg->data[msg->used-3]='\0';
+    xbt_die(msg->data);
+  }
   xbt_main_func_t parse_code = SIMIX_get_registered_function(process->function);
   xbt_assert(parse_code, "Function '%s' unknown", process->function);