This commit is contained in:
Alexander Tokmakov 2024-04-09 23:43:40 +02:00
parent 5a897bc43e
commit dedc25fd34
4 changed files with 14 additions and 9 deletions

View File

@ -214,7 +214,7 @@ void Connection::connect(const ConnectionTimeouts & timeouts)
DNSResolver::instance().removeHostFromCache(host); DNSResolver::instance().removeHostFromCache(host);
/// Add server address to exception. Exception will preserve stack trace. /// Add server address to exception. Exception will preserve stack trace.
e.addMessage("({})", getDescription()); e.addMessage("({})", getDescription(/*with_extra*/ true));
throw; throw;
} }
catch (Poco::Net::NetException & e) catch (Poco::Net::NetException & e)
@ -225,7 +225,7 @@ void Connection::connect(const ConnectionTimeouts & timeouts)
DNSResolver::instance().removeHostFromCache(host); DNSResolver::instance().removeHostFromCache(host);
/// Add server address to exception. Also Exception will remember new stack trace. It's a pity that more precise exception type is lost. /// Add server address to exception. Also Exception will remember new stack trace. It's a pity that more precise exception type is lost.
throw NetException(ErrorCodes::NETWORK_ERROR, "{} ({})", e.displayText(), getDescription()); throw NetException(ErrorCodes::NETWORK_ERROR, "{} ({})", e.displayText(), getDescription(/*with_extra*/ true));
} }
catch (Poco::TimeoutException & e) catch (Poco::TimeoutException & e)
{ {
@ -241,7 +241,7 @@ void Connection::connect(const ConnectionTimeouts & timeouts)
ErrorCodes::SOCKET_TIMEOUT, ErrorCodes::SOCKET_TIMEOUT,
"{} ({}, connection timeout {} ms)", "{} ({}, connection timeout {} ms)",
e.displayText(), e.displayText(),
getDescription(), getDescription(/*with_extra*/ true),
connection_timeout.totalMilliseconds()); connection_timeout.totalMilliseconds());
} }
} }
@ -473,8 +473,10 @@ const String & Connection::getDefaultDatabase() const
return default_database; return default_database;
} }
const String & Connection::getDescription() const const String & Connection::getDescription(bool with_extra) const
{ {
if (with_extra)
return full_description;
return description; return description;
} }
@ -1227,10 +1229,12 @@ void Connection::setDescription()
description += ", " + ip_address; description += ", " + ip_address;
} }
full_description = description;
if (const auto * socket_ = getSocket()) if (const auto * socket_ = getSocket())
{ {
description += ", local address: "; full_description += ", local address: ";
description += socket_->address().toString(); full_description += socket_->address().toString();
} }
} }

View File

@ -89,7 +89,7 @@ public:
const String & getServerDisplayName(const ConnectionTimeouts & timeouts) override; const String & getServerDisplayName(const ConnectionTimeouts & timeouts) override;
/// For log and exception messages. /// For log and exception messages.
const String & getDescription() const override; const String & getDescription(bool with_extra = false) const override;
const String & getHost() const; const String & getHost() const;
UInt16 getPort() const; UInt16 getPort() const;
const String & getDefaultDatabase() const; const String & getDefaultDatabase() const;
@ -187,6 +187,7 @@ private:
/// For messages in log and in exceptions. /// For messages in log and in exceptions.
String description; String description;
String full_description;
void setDescription(); void setDescription();
/// Returns resolved address if it was resolved. /// Returns resolved address if it was resolved.

View File

@ -88,7 +88,7 @@ public:
virtual const String & getServerTimezone(const ConnectionTimeouts & timeouts) = 0; virtual const String & getServerTimezone(const ConnectionTimeouts & timeouts) = 0;
virtual const String & getServerDisplayName(const ConnectionTimeouts & timeouts) = 0; virtual const String & getServerDisplayName(const ConnectionTimeouts & timeouts) = 0;
virtual const String & getDescription() const = 0; virtual const String & getDescription(bool with_extra = false) const = 0;
virtual std::vector<std::pair<String, String>> getPasswordComplexityRules() const = 0; virtual std::vector<std::pair<String, String>> getPasswordComplexityRules() const = 0;

View File

@ -90,7 +90,7 @@ public:
const String & getServerTimezone(const ConnectionTimeouts & timeouts) override; const String & getServerTimezone(const ConnectionTimeouts & timeouts) override;
const String & getServerDisplayName(const ConnectionTimeouts & timeouts) override; const String & getServerDisplayName(const ConnectionTimeouts & timeouts) override;
const String & getDescription() const override { return description; } const String & getDescription([[maybe_unused]] bool with_extra = false) const override { return description; }
std::vector<std::pair<String, String>> getPasswordComplexityRules() const override { return {}; } std::vector<std::pair<String, String>> getPasswordComplexityRules() const override { return {}; }