Commit da1864fd authored by Rob Latham's avatar Rob Latham

add a "bake_perror" for error codes

parent 2ae5219c
......@@ -39,6 +39,14 @@ typedef struct {
#define BAKE_ERR_REMI (-10) /* Error related to REMI */
#define BAKE_ERR_OP_UNSUPPORTED (-11) /* Operation not supported */
/**
* Print bake errors in human-friendly form
*
* @param a string to print out before the error
* @param ret error code from a bake routine
*/
void bake_perror(char *s, int ret);
#ifdef __cplusplus
}
#endif
......
noinst_LTLIBRARIES = \
src/libutil.la
src_libutil_la_SOURCES = \
src/util.c
src_libbake_client_la_SOURCES += \
src/bake-client.c
src_libbake_client_la_LIBADD = src/libutil.la
src_libbake_server_la_SOURCES += \
src/bake-server.c
src_libbake_server_la_LIBADD = src/libutil.la
src_bake_server_daemon_LDADD = src/libbake-server.la
src_bake_mkpool_LDADD = src/libbake-server.la
......
......@@ -63,7 +63,7 @@ int main(int argc, char **argv)
ret = bake_client_init(mid, &bcl);
if(ret != 0)
{
fprintf(stderr, "Error: bake_client_init()\n");
bake_perror( "Error: bake_client_init()", ret);
margo_finalize(mid);
return -1;
}
......@@ -80,7 +80,7 @@ int main(int argc, char **argv)
ret = bake_provider_handle_create(bcl, svr_addr, mplex_id, &bph);
if(ret < 0)
{
fprintf(stderr, "Error: bake_provider_handle_create()\n");
bake_perror("Error: bake_provider_handle_create()", ret);
margo_addr_free(mid, svr_addr);
bake_client_finalize(bcl);
margo_finalize(mid);
......@@ -116,7 +116,7 @@ int main(int argc, char **argv)
ret = bake_get_size(bph, rid, &check_size);
if(ret != 0)
{
fprintf(stderr, "Error: bake_get_size()\n");
bake_perror("Error: bake_get_size()", ret);
bake_provider_handle_release(bph);
margo_addr_free(mid, svr_addr);
bake_client_finalize(bcl);
......@@ -185,7 +185,7 @@ int main(int argc, char **argv)
margo_addr_free(mid, svr_addr);
bake_client_finalize(bcl);
margo_finalize(mid);
fprintf(stderr, "Error: bake_read()\n");
bake_perror("Error: bake_read()", ret);
return(-1);
}
......
......@@ -93,7 +93,7 @@ int main(int argc, char **argv)
ret = bake_client_init(mid, &bcl);
if(ret != 0)
{
fprintf(stderr, "Error: bake_client_init()\n");
bake_perror("Error: bake_client_init()", ret);
margo_finalize(mid);
munmap(local_region, statbuf.st_size);
close(fd);
......@@ -119,7 +119,7 @@ int main(int argc, char **argv)
margo_finalize(mid);
munmap(local_region, statbuf.st_size);
close(fd);
fprintf(stderr, "Error: bake_provider_handle_create()\n");
bake_perror("Error: bake_provider_handle_create()", ret);
return(-1);
}
......@@ -132,7 +132,7 @@ int main(int argc, char **argv)
margo_finalize(mid);
munmap(local_region, statbuf.st_size);
close(fd);
fprintf(stderr, "Error: bake_probe()\n");
bake_perror( "Error: bake_probe()", ret);
return(-1);
}
......@@ -156,7 +156,7 @@ int main(int argc, char **argv)
margo_finalize(mid);
munmap(local_region, statbuf.st_size);
close(fd);
fprintf(stderr, "Error: bake_create()\n");
bake_perror("Error: bake_create()", ret);
return(-1);
}
......@@ -175,7 +175,7 @@ int main(int argc, char **argv)
margo_finalize(mid);
munmap(local_region, statbuf.st_size);
close(fd);
fprintf(stderr, "Error: bake_write()\n");
bake_perror("bake_write():", ret);
return(-1);
}
......@@ -189,7 +189,7 @@ int main(int argc, char **argv)
margo_addr_free(mid, svr_addr);
bake_client_finalize(bcl);
margo_finalize(mid);
fprintf(stderr, "Error: bake_persist()\n");
bake_perror("Error: bake_persist()", ret);
return(-1);
}
......@@ -202,7 +202,7 @@ int main(int argc, char **argv)
margo_addr_free(mid, svr_addr);
bake_client_finalize(bcl);
margo_finalize(mid);
fprintf(stderr, "Error: bake_get_size()\n");
bake_perror("Error: bake_get_size()", ret);
return(-1);
}
......
......@@ -79,7 +79,7 @@ int main(int argc, char **argv)
ret = bake_client_init(mid, &bcl);
if(ret != 0)
{
fprintf(stderr, "Error: bake_client_init()\n");
bake_perror("Error: bake_client_init()", ret);
margo_finalize(mid);
return -1;
}
......@@ -96,7 +96,7 @@ int main(int argc, char **argv)
ret = bake_probe(bph, 1, &bti, &num_targets);
if(ret < 0)
{
fprintf(stderr, "Error: bake_probe()\n");
bake_perror( "Error: bake_probe()", ret);
bake_provider_handle_release(bph);
margo_addr_free(mid, svr_addr);
bake_client_finalize(bcl);
......
......@@ -170,7 +170,7 @@ int main(int argc, char **argv)
if(ret != 0)
{
fprintf(stderr, "Error: bake_provider_register()\n");
bake_perror( "Error: bake_provider_register()", ret);
margo_finalize(mid);
return(-1);
}
......@@ -179,7 +179,7 @@ int main(int argc, char **argv)
if(ret != 0)
{
fprintf(stderr, "Error: bake_provider_add_storage_target()\n");
bake_perror("Error: bake_provider_add_storage_target()", ret);
margo_finalize(mid);
return(-1);
}
......@@ -200,7 +200,7 @@ int main(int argc, char **argv)
if(ret != 0)
{
fprintf(stderr, "Error: bake_provider_register()\n");
bake_perror("Error: bake_provider_register()", ret);
margo_finalize(mid);
return(-1);
}
......@@ -211,7 +211,7 @@ int main(int argc, char **argv)
if(ret != 0)
{
fprintf(stderr, "Error: bake_provider_add_storage_target()\n");
bake_perror("Error: bake_provider_add_storage_target()", ret);
margo_finalize(mid);
return(-1);
}
......
......@@ -59,7 +59,7 @@ int main(int argc, char **argv)
if(ret < 0)
{
fprintf(stderr, "Error: bake_probe_instance()\n");
bake_perror("Error: bake_probe_instance()", ret);
margo_addr_free(mid, svr_addr);
margo_finalize(mid);
return(-1);
......
/*
* (C) 2019 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include "bake-config.h"
#include "bake.h"
#include <stdio.h>
static char * bake_err_str(int ret)
{
switch(ret) {
case BAKE_SUCCESS:
return "Success";
break;
case BAKE_ERR_ALLOCATION:
return "Error allocating something";
break;
case BAKE_ERR_INVALID_ARG:
return "An argument is invalid";
break;
case BAKE_ERR_MERCURY:
return "An error happend calling a Mercury function";
break;
case BAKE_ERR_ARGOBOTS:
return "An error happened calling an Argobots function";
break;
case BAKE_ERR_PMEM:
return "An error happend calling a PMDK function";
break;
case BAKE_ERR_UNKNOWN_TARGET:
return "Target refered to by id is not know to provider";
break;
case BAKE_ERR_UNKNOWN_PROVIDER:
return "Provider id could not be matched with a provider";
break;
case BAKE_ERR_UNKNOWN_REGION:
return "Region id could not be found";
break;
case BAKE_ERR_OUT_OF_BOUNDS:
return "Attempting an out of bound access";
break;
case BAKE_ERR_REMI:
return "Error related to REMI";
break;
case BAKE_ERR_OP_UNSUPPORTED:
return "Operation not supported";
break;
default:
return "Unknown error";
break;
}
}
void bake_perror(char *s, int err)
{
char error_string[256];
char *p;
int ret;
ret = snprintf(error_string, 256,"%s", s);
p = error_string+ret;
snprintf(p, 256-ret, " (%d) %s", err, bake_err_str(err) );
error_string[255] = '\0';
fprintf(stderr, "%s\n", error_string);
}
......@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
ret = bake_client_init(mid, &bcl);
if(ret != 0)
{
fprintf(stderr, "Error: bake_client_init()\n");
bake_perror( "Error: bake_client_init()", ret);
margo_finalize(mid);
return -1;
}
......@@ -80,7 +80,7 @@ int main(int argc, char *argv[])
ret = bake_provider_handle_create(bcl, svr_addr, mplex_id, &bph);
if(ret != 0)
{
fprintf(stderr, "Error: bake_provider_handle_create()\n");
bake_perror( "Error: bake_provider_handle_create()", ret);
margo_addr_free(mid, svr_addr);
bake_client_finalize(bcl);
margo_finalize(mid);
......@@ -92,7 +92,7 @@ int main(int argc, char *argv[])
ret = bake_probe(bph, 1, &bti, &num_targets);
if(ret != 0)
{
fprintf(stderr, "Error: bake_probe()\n");
bake_perror( "Error: bake_probe()", ret);
bake_provider_handle_release(bph);
margo_addr_free(mid, svr_addr);
bake_client_finalize(bcl);
......@@ -119,7 +119,7 @@ int main(int argc, char *argv[])
ret = bake_create_write_persist(bph, bti, buf, buf_size, &the_rid);
if(ret != 0)
{
fprintf(stderr, "Error: bake_create_write_persist()\n");
bake_perror("Error: bake_create_write_persist()", ret);
free(buf);
bake_provider_handle_release(bph);
margo_addr_free(mid, svr_addr);
......@@ -137,7 +137,7 @@ int main(int argc, char *argv[])
ret = bake_read(bph, the_rid, 0, buf, buf_size, &bytes_read);
if(ret != 0)
{
fprintf(stderr, "Error: bake_read()\n");
bake_perror( "Error: bake_read()", ret);
free(buf);
bake_provider_handle_release(bph);
margo_addr_free(mid, svr_addr);
......@@ -161,7 +161,7 @@ int main(int argc, char *argv[])
ret = bake_remove(bph, the_rid);
if (ret != 0)
{
fprintf(stderr, "Error: unable to remove the created BAKE region\n");
bake_perror( "Error: unable to remove the created BAKE region", ret);
free(buf);
bake_provider_handle_release(bph);
margo_addr_free(mid, svr_addr);
......
......@@ -63,7 +63,7 @@ int main(int argc, char *argv[])
ret = bake_client_init(mid, &bcl);
if(ret != 0)
{
fprintf(stderr, "Error: bake_client_init()\n");
bake_perror( "Error: bake_client_init()", ret);
margo_finalize(mid);
return -1;
}
......@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
hret = margo_addr_lookup(mid, bake_svr_addr_str, &svr_addr);
if(hret != HG_SUCCESS)
{
fprintf(stderr, "Error: margo_addr_lookup()\n");
bake_perror( "Error: margo_addr_lookup()", ret);
bake_client_finalize(bcl);
margo_finalize(mid);
return(-1);
......@@ -82,7 +82,7 @@ int main(int argc, char *argv[])
ret = bake_provider_handle_create(bcl, svr_addr, mplex_id, &bph);
if(ret != 0)
{
fprintf(stderr, "Error: bake_provider_handle_create()\n");
bake_perror( "Error: bake_provider_handle_create()", ret);
margo_addr_free(mid, svr_addr);
bake_client_finalize(bcl);
margo_finalize(mid);
......@@ -94,7 +94,7 @@ int main(int argc, char *argv[])
ret = bake_probe(bph, 1, &bti, &num_targets);
if(ret != 0)
{
fprintf(stderr, "Error: bake_probe()\n");
bake_perror( "Error: bake_probe()", ret);
bake_provider_handle_release(bph);
margo_addr_free(mid, svr_addr);
bake_client_finalize(bcl);
......@@ -108,7 +108,7 @@ int main(int argc, char *argv[])
ret = bake_create_write_persist(bph, bti, test_str, buf_size, &the_rid);
if(ret != 0)
{
fprintf(stderr, "Error: bake_create_write_persist()\n");
bake_perror( "Error: bake_create_write_persist()", ret);
bake_provider_handle_release(bph);
margo_addr_free(mid, svr_addr);
bake_client_finalize(bcl);
......@@ -125,7 +125,7 @@ int main(int argc, char *argv[])
ret = bake_read(bph, the_rid, 0, buf, buf_size, &bytes_read);
if(ret != 0)
{
fprintf(stderr, "Error: bake_read()\n");
bake_perror( "Error: bake_read()", ret);
free(buf);
bake_provider_handle_release(bph);
margo_addr_free(mid, svr_addr);
......
......@@ -159,7 +159,7 @@ int main(int argc, char **argv)
ret = bake_client_init(mid, &g_proxy_svr_ctx->bcl);
if(ret != 0)
{
fprintf(stderr, "Error: bake_client_init()\n");
bake_perror( "Error: bake_client_init()\n", ret);
margo_finalize(mid);
return -1;
}
......@@ -184,7 +184,7 @@ int main(int argc, char **argv)
if(ret != 0)
{
fprintf(stderr, "Error: bake_provider_handle_create()\n");
bake_perror( "Error: bake_provider_handle_create()", ret);
bake_client_finalize(g_proxy_svr_ctx->bcl);
margo_finalize(mid);
return -1;
......@@ -196,7 +196,7 @@ int main(int argc, char **argv)
1, &g_proxy_svr_ctx->svr_bti, &num_targets);
if(ret < 0)
{
fprintf(stderr, "Error: bake_probe_instance()\n");
bake_perror( "Error: bake_probe_instance()", ret);
return(-1);
}
margo_addr_free(mid, bake_svr_addr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment