From 61ceafc8bba3747b492f8b0f779793813a682ecb Mon Sep 17 00:00:00 2001 From: John Spray Date: Wed, 27 Sep 2017 14:59:26 -0400 Subject: [PATCH] tools: handle decode errors in monstore tool Print a single line message instead of dumping a backtrace. Signed-off-by: John Spray --- src/tools/ceph_monstore_tool.cc | 49 +++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/src/tools/ceph_monstore_tool.cc b/src/tools/ceph_monstore_tool.cc index 8c941443d818f..b7a3ea20c7fc6 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 { -- 2.39.5