]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rados: gracefully report errors from 'ls'
authorSage Weil <sage@newdream.net>
Wed, 4 Jan 2012 18:40:06 +0000 (10:40 -0800)
committerSage Weil <sage@newdream.net>
Wed, 4 Jan 2012 18:40:06 +0000 (10:40 -0800)
Catch the exception thrown by the iterator when the OSD returns errors.

Signed-off-by: Sage Weil <sage@newdream.net>
src/librados.cc
src/rados.cc

index 8323b2081f7c1baea7812c2d3dda6e8505cdd5e5..59ba318542dd0dd9d882bbf387523bcb63aaaa44 100644 (file)
@@ -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());
   }
 
index 1ea886d794999afd24de72fde9222bc2bc1ede44..049158e384260a2a19b7b2a4df4b54a4b541eb05 100644 (file)
@@ -35,6 +35,7 @@ using namespace librados;
 #include <sstream>
 #include <errno.h>
 #include <dirent.h>
+#include <stdexcept>
 
 #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)