]> git.meshlink.io Git - meshlink/commitdiff
Add proper error reporting to the chat examples.
authorGuus Sliepen <guus@sliepen.org>
Wed, 30 Jul 2014 15:25:42 +0000 (17:25 +0200)
committerGuus Sliepen <guus@sliepen.org>
Wed, 30 Jul 2014 15:25:42 +0000 (17:25 +0200)
examples/chat.c
examples/chatpp.cc

index 3dbbb86019bb8713d47b7cdcd1068f3a90d638fd..ace1e783883a4176d9516e34efbc74147a336edb 100644 (file)
@@ -69,7 +69,7 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) {
 
                meshlink_node_t *node = meshlink_get_node(mesh, arg);
                if(!node) {
-                       fprintf(stderr, "Unknown node '%s'\n", arg);
+                       fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink_strerror(meshlink_errno));
                        return;
                }
 
@@ -80,9 +80,9 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) {
                if(!arg) {
                        nodes = meshlink_get_all_nodes(mesh, nodes, &nnodes);
                        if(!nnodes) {
-                               fprintf(stderr, "No nodes known!\n");
+                               fprintf(stderr, "Could not get list of nodes: %s\n", meshlink_strerror(meshlink_errno));
                        } else {
-                               printf("Known nodes:");
+                               printf("%zu known nodes:", nnodes);
                                for(int i = 0; i < nnodes; i++)
                                        printf(" %s", nodes[i]->name);
                                printf("\n");
@@ -90,7 +90,7 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) {
                } else {
                        meshlink_node_t *node = meshlink_get_node(mesh, arg);
                        if(!node) {
-                               fprintf(stderr, "Unknown node '%s'\n", arg);
+                               fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink_strerror(meshlink_errno));
                        } else {
                                printf("Node %s found\n", arg);
                        }
@@ -153,7 +153,7 @@ static void parse_input(meshlink_handle_t *mesh, char *buf) {
 
                destination = meshlink_get_node(mesh, buf);
                if(!destination) {
-                       fprintf(stderr, "Unknown node '%s'\n", buf);
+                       fprintf(stderr, "Error looking up '%s': %s\n", buf, meshlink_strerror(meshlink_errno));
                        return;
                }
        }
@@ -184,7 +184,7 @@ int main(int argc, char *argv[]) {
 
        meshlink_handle_t *mesh = meshlink_open(confbase, nick);
        if(!mesh) {
-               fprintf(stderr, "Could not open MeshLink!\n");
+               fprintf(stderr, "Could not open MeshLink: %s\n", meshlink_strerror(meshlink_errno));
                return 1;
        }
 
index 00863d501815cee2c5064d945987a27e3359e79e..f21e96dee2003d7d1cbe8913e3b2987999102473 100644 (file)
@@ -69,7 +69,7 @@ static void parse_command(meshlink::mesh *mesh, char *buf) {
 
                meshlink::node *node = mesh->get_node(arg);
                if(!node) {
-                       fprintf(stderr, "Unknown node '%s'\n", arg);
+                       fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink::strerror());
                        return;
                }
 
@@ -79,10 +79,10 @@ static void parse_command(meshlink::mesh *mesh, char *buf) {
        } else if(!strcasecmp(buf, "who")) {
                if(!arg) {
                        nodes = mesh->get_all_nodes(nodes, &nnodes);
-                       if(!nnodes) {
-                               fprintf(stderr, "No nodes known!\n");
+                       if(!nodes) {
+                               fprintf(stderr, "Could not get list of nodes: %s\n", meshlink::strerror());
                        } else {
-                               printf("Known nodes:");
+                               printf("%d known nodes:", nnodes);
                                for(size_t i = 0; i < nnodes; i++)
                                        printf(" %s", nodes[i]->name);
                                printf("\n");
@@ -90,7 +90,7 @@ static void parse_command(meshlink::mesh *mesh, char *buf) {
                } else {
                        meshlink::node *node = mesh->get_node(arg);
                        if(!node) {
-                               fprintf(stderr, "Unknown node '%s'\n", arg);
+                               fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink::strerror());
                        } else {
                                printf("Node %s found\n", arg);
                        }
@@ -153,7 +153,7 @@ static void parse_input(meshlink::mesh *mesh, char *buf) {
 
                destination = mesh->get_node(buf);
                if(!destination) {
-                       fprintf(stderr, "Unknown node '%s'\n", buf);
+                       fprintf(stderr, "Error looking up '%s': %s\n", buf, meshlink::strerror());
                        return;
                }
        }
@@ -184,7 +184,7 @@ int main(int argc, char *argv[]) {
 
        meshlink::mesh *mesh = meshlink::open(confbase, nick);
        if(!mesh) {
-               fprintf(stderr, "Could not open MeshLink!\n");
+               fprintf(stderr, "Could not open MeshLink: %s\n", meshlink::strerror());
                return 1;
        }