From f742b0aa0fa7f6a760002e0c77ae0403bb4e4127 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Wed, 30 Jul 2014 17:25:42 +0200 Subject: [PATCH] Add proper error reporting to the chat examples. --- examples/chat.c | 12 ++++++------ examples/chatpp.cc | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/chat.c b/examples/chat.c index 3dbbb860..ace1e783 100644 --- a/examples/chat.c +++ b/examples/chat.c @@ -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; } diff --git a/examples/chatpp.cc b/examples/chatpp.cc index 00863d50..f21e96de 100644 --- a/examples/chatpp.cc +++ b/examples/chatpp.cc @@ -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; } -- 2.39.5