From: Martin Quinson Date: Sun, 7 Feb 2016 13:49:01 +0000 (+0100) Subject: Nice error message when creating a process on non-existing host X-Git-Tag: v3_13~951 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/9ae4732223b7623a2956ac7849e5e6c8335ba181 Nice error message when creating a process on non-existing host --- diff --git a/include/xbt/strbuff.h b/include/xbt/strbuff.h index 79b2658265..d76decc4b1 100644 --- a/include/xbt/strbuff.h +++ b/include/xbt/strbuff.h @@ -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 diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index e2968b1da6..f734c0b1b2 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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);