]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools: handle decode errors in monstore tool
authorJohn Spray <john.spray@redhat.com>
Wed, 27 Sep 2017 18:59:26 +0000 (14:59 -0400)
committerJohn Spray <john.spray@redhat.com>
Thu, 28 Sep 2017 10:07:56 +0000 (11:07 +0100)
Print a single line message instead of dumping
a backtrace.

Signed-off-by: John Spray <john.spray@redhat.com>
src/tools/ceph_monstore_tool.cc

index 8c941443d818ffe65ea787bf70825cd0df241fb3..b7a3ea20c7fc68637306a45e50a8b5d8d311fa86 100644 (file)
@@ -914,28 +914,35 @@ int main(int argc, char **argv) {
     if (readable) {
       stringstream ss;
       bufferlist out;
-      if (map_type == "monmap") {
-        MonMap monmap;
-        monmap.decode(bl);
-        monmap.print(ss);
-      } else if (map_type == "osdmap") {
-        OSDMap osdmap;
-        osdmap.decode(bl);
-        osdmap.print(ss);
-      } else if (map_type == "mdsmap") {
-        MDSMap mdsmap;
-        mdsmap.decode(bl);
-        mdsmap.print(ss);
-      } else if (map_type == "crushmap") {
-        CrushWrapper cw;
-        bufferlist::iterator it = bl.begin();
-        cw.decode(it);
-        CrushCompiler cc(cw, std::cerr, 0);
-        cc.decompile(ss);
-      } else {
-        std::cerr << "This type of readable map does not exist: " << map_type << std::endl
-                  << "You can only specify[osdmap|monmap|mdsmap|crushmap]" << std::endl;
+      try {
+        if (map_type == "monmap") {
+          MonMap monmap;
+          monmap.decode(bl);
+          monmap.print(ss);
+        } else if (map_type == "osdmap") {
+          OSDMap osdmap;
+          osdmap.decode(bl);
+          osdmap.print(ss);
+        } else if (map_type == "mdsmap") {
+          MDSMap mdsmap;
+          mdsmap.decode(bl);
+          mdsmap.print(ss);
+        } else if (map_type == "crushmap") {
+          CrushWrapper cw;
+          bufferlist::iterator it = bl.begin();
+          cw.decode(it);
+          CrushCompiler cc(cw, std::cerr, 0);
+          cc.decompile(ss);
+        } else {
+          std::cerr << "This type of readable map does not exist: " << map_type
+                    << std::endl << "You can only specify[osdmap|monmap|mdsmap"
+                    "|crushmap]" << std::endl;
+        }
+      } catch (const buffer::error &err) {
+        std::cerr << "Could not decode for human readable output (you may still"
+                     " use non-readable mode).  Detail: " << err << std::endl;
       }
+
       out.append(ss);
       out.write_fd(fd);
     } else {