diff --git a/src/Common/Exception.cpp b/src/Common/Exception.cpp index dd78d0ec9fc..e0d5fb321dd 100644 --- a/src/Common/Exception.cpp +++ b/src/Common/Exception.cpp @@ -34,9 +34,9 @@ namespace ErrorCodes extern const int CANNOT_MREMAP; } - -Exception::Exception(const std::string & msg, int code) - : Poco::Exception(msg, code) +/// Aborts the process if error code is LOGICAL_ERROR. +/// Increments error codes statistics. +void handle_error_code(const std::string & msg, int code) // NOLINT { // In debug builds and builds with sanitizers, treat LOGICAL_ERROR as an assertion failure. // Log the message before we fail. @@ -50,6 +50,18 @@ Exception::Exception(const std::string & msg, int code) ErrorCodes::increment(code); } +Exception::Exception(const std::string & msg, int code) + : Poco::Exception(msg, code) +{ + handle_error_code(msg, code); +} + +Exception::Exception(const std::string & msg, const Exception & nested, int code) + : Poco::Exception(msg, nested, code) +{ + handle_error_code(msg, code); +} + Exception::Exception(CreateFromPocoTag, const Poco::Exception & exc) : Poco::Exception(exc.displayText(), ErrorCodes::POCO_EXCEPTION) { diff --git a/src/Common/Exception.h b/src/Common/Exception.h index 0096c87d6e5..3da2e2fb0d0 100644 --- a/src/Common/Exception.h +++ b/src/Common/Exception.h @@ -25,6 +25,7 @@ class Exception : public Poco::Exception public: Exception() = default; Exception(const std::string & msg, int code); + Exception(const std::string & msg, const Exception & nested, int code); Exception(int code, const std::string & message) : Exception(message, code) diff --git a/src/Disks/S3/DiskS3.cpp b/src/Disks/S3/DiskS3.cpp index 5b771eb3c85..3f3d23938ba 100644 --- a/src/Disks/S3/DiskS3.cpp +++ b/src/Disks/S3/DiskS3.cpp @@ -175,7 +175,7 @@ struct DiskS3::Metadata if (e.code() == ErrorCodes::UNKNOWN_FORMAT) throw; - throw Exception("Failed to read metadata file: " + e.message(), ErrorCodes::UNKNOWN_FORMAT); + throw Exception("Failed to read metadata file", e, ErrorCodes::UNKNOWN_FORMAT); } } @@ -729,7 +729,7 @@ void DiskS3::removeMeta(const String & path, AwsS3KeyKeeper & keys) file.remove(); } } - catch (Exception & e) + catch (const Exception & e) { /// If it's impossible to read meta - just remove it from FS. if (e.code() == ErrorCodes::UNKNOWN_FORMAT) @@ -738,7 +738,7 @@ void DiskS3::removeMeta(const String & path, AwsS3KeyKeeper & keys) &Poco::Logger::get("DiskS3"), "Metadata file {} can't be read by reason: {}. Removing it forcibly.", backQuote(path), - e.message()); + e.nested() ? e.nested()->message() : e.message()); file.remove(); }