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);
/// Add server address to exception. Exception will preserve stack trace.
e.addMessage("({})", getDescription());
e.addMessage("({})", getDescription(/*with_extra*/ true));
throw;
}
catch (Poco::Net::NetException & e)
@ -225,7 +225,7 @@ void Connection::connect(const ConnectionTimeouts & timeouts)
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.
throw NetException(ErrorCodes::NETWORK_ERROR, "{} ({})", e.displayText(), getDescription());
throw NetException(ErrorCodes::NETWORK_ERROR, "{} ({})", e.displayText(), getDescription(/*with_extra*/ true));
}
catch (Poco::TimeoutException & e)
{
@ -241,7 +241,7 @@ void Connection::connect(const ConnectionTimeouts & timeouts)
ErrorCodes::SOCKET_TIMEOUT,
"{} ({}, connection timeout {} ms)",
e.displayText(),
getDescription(),
getDescription(/*with_extra*/ true),
connection_timeout.totalMilliseconds());
}
}
@ -473,8 +473,10 @@ const String & Connection::getDefaultDatabase() const
return default_database;
}
const String & Connection::getDescription() const
const String & Connection::getDescription(bool with_extra) const
{
if (with_extra)
return full_description;
return description;
}
@ -1227,10 +1229,12 @@ void Connection::setDescription()
description += ", " + ip_address;
}
full_description = description;
if (const auto * socket_ = getSocket())
{
description += ", local address: ";
description += socket_->address().toString();
full_description += ", local address: ";
full_description += socket_->address().toString();
}
}

View File

@ -89,7 +89,7 @@ public:
const String & getServerDisplayName(const ConnectionTimeouts & timeouts) override;
/// For log and exception messages.
const String & getDescription() const override;
const String & getDescription(bool with_extra = false) const override;
const String & getHost() const;
UInt16 getPort() const;
const String & getDefaultDatabase() const;
@ -187,6 +187,7 @@ private:
/// For messages in log and in exceptions.
String description;
String full_description;
void setDescription();
/// 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 & 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;

View File

@ -90,7 +90,7 @@ public:
const String & getServerTimezone(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 {}; }