From: John Spray Date: Wed, 27 Sep 2017 18:59:26 +0000 (-0400) Subject: tools: handle decode errors in monstore tool X-Git-Tag: v13.0.1~732^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=61ceafc8bba3747b492f8b0f779793813a682ecb;p=ceph.git tools: handle decode errors in monstore tool Print a single line message instead of dumping a backtrace. Signed-off-by: John Spray --- diff --git a/src/tools/ceph_monstore_tool.cc b/src/tools/ceph_monstore_tool.cc index 8c941443d818..b7a3ea20c7fc 100644 --- a/src/tools/ceph_monstore_tool.cc +++ b/src/tools/ceph_monstore_tool.cc @@ -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 {