From 56d3cb514aec4c0fee132cf989e0bebcdcd7a880 Mon Sep 17 00:00:00 2001 From: Benny Halevy Date: Mon, 24 May 2021 14:38:08 +0300 Subject: [PATCH] sstables: parse statistics: improve error handling Properly return malformed_sstable_exception if the statistics file fails to parse. Test: unit(dev) Signed-off-by: Benny Halevy Message-Id: <20210524113808.973951-1-bhalevy@scylladb.com> --- sstables/sstables.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sstables/sstables.cc b/sstables/sstables.cc index 88cf9826ac..c25b0220e0 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -632,18 +632,25 @@ future<> parse(const schema& schema, sstable_version_types v, random_access_read return parse(schema, v, in, s.contents[type]); case metadata_type::Serialization: if (v < sstable_version_types::mc) { - throw std::runtime_error( + throw malformed_sstable_exception( "Statistics is malformed: SSTable is in 2.x format but contains serialization header."); } else { return parse(schema, v, in, s.contents[type]); } return make_ready_future<>(); default: - sstlog.warn("Invalid metadata type at Statistics file: {} ", int(type)); - return make_ready_future<>(); + throw malformed_sstable_exception(fmt::format("Invalid metadata type at Statistics file: {} ", int(type))); } }); }); + }).handle_exception([] (std::exception_ptr ex) { + try { + std::rethrow_exception(ex); + } catch (const malformed_sstable_exception&) { + throw; + } catch (...) { + throw malformed_sstable_exception(fmt::format("Statistics file is malformed: {}", ex)); + } }); }