From 54f36f0bf535c571243972882759db5f30607cfd Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 4 Jan 2012 10:40:06 -0800 Subject: [PATCH] rados: gracefully report errors from 'ls' Catch the exception thrown by the iterator when the OSD returns errors. Signed-off-by: Sage Weil --- src/librados.cc | 2 +- src/rados.cc | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/librados.cc b/src/librados.cc index 8323b2081f7c1..59ba318542dd0 100644 --- a/src/librados.cc +++ b/src/librados.cc @@ -2625,7 +2625,7 @@ void librados::ObjectIterator::get_next() } else if (ret) { ostringstream oss; - oss << "rados_objects_list_next returned " << ret; + oss << "rados returned " << cpp_strerror(ret); throw std::runtime_error(oss.str()); } diff --git a/src/rados.cc b/src/rados.cc index 1ea886d794999..049158e384260 100644 --- a/src/rados.cc +++ b/src/rados.cc @@ -35,6 +35,7 @@ using namespace librados; #include #include #include +#include #include "common/errno.h" @@ -862,13 +863,19 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, outstream = new ofstream(nargs[1]); { - librados::ObjectIterator i = io_ctx.objects_begin(); - librados::ObjectIterator i_end = io_ctx.objects_end(); - for (; i != i_end; ++i) { - if (i->second.size()) - *outstream << i->first << "\t" << i->second << std::endl; - else - *outstream << i->first << std::endl; + try { + librados::ObjectIterator i = io_ctx.objects_begin(); + librados::ObjectIterator i_end = io_ctx.objects_end(); + for (; i != i_end; ++i) { + if (i->second.size()) + *outstream << i->first << "\t" << i->second << std::endl; + else + *outstream << i->first << std::endl; + } + } + catch (const std::runtime_error& e) { + cerr << e.what() << std::endl; + return 1; } } if (!stdout) -- 2.39.5