1
0
mirror of https://github.com/anope/anope.git synced 2026-06-26 08:56:39 +02:00

Replace convertTo/stringify with non-throwing alternatives.

Having these throw is terrible for ergonomics and there are loads
of places where the exception was either silently ignored or not
handled at all. Having a function which returns an optional and
another that returns a default works a lot better imo.
This commit is contained in:
Sadie Powell
2024-03-11 13:53:05 +00:00
parent e2df7d4d01
commit 29e7674e56
76 changed files with 572 additions and 810 deletions
+10 -17
View File
@@ -398,7 +398,7 @@ bool ModeManager::AddUserMode(UserMode *um)
if (um->name.empty())
{
um->name = stringify(++GenericUserModes);
um->name = Anope::ToString(++GenericUserModes);
Log() << "ModeManager: Added generic support for user mode " << um->mchar;
}
@@ -425,7 +425,7 @@ bool ModeManager::AddChannelMode(ChannelMode *cm)
if (cm->name.empty())
{
cm->name = stringify(++GenericChannelModes);
cm->name = Anope::ToString(++GenericChannelModes);
Log() << "ModeManager: Added generic support for channel mode " << cm->mchar;
}
@@ -783,22 +783,15 @@ Entry::Entry(const Anope::string &m, const Anope::string &fh) : name(m), mask(fh
&cidr_range = this->host.substr(sl + 1);
sockaddrs addr(cidr_ip);
try
auto range = Anope::TryConvert<unsigned short>(cidr_range);
if (addr.valid() && range.has_value())
{
if (addr.valid() && cidr_range.is_pos_number_only())
{
this->cidr_len = convertTo<unsigned short>(cidr_range);
this->cidr_len = range.value();
this->host = cidr_ip;
this->family = addr.family();
/* If we got here, cidr_len is a valid number. */
this->host = cidr_ip;
this->family = addr.family();
Log(LOG_DEBUG) << "Ban " << mask << " has cidr " << this->cidr_len;
}
Log(LOG_DEBUG) << "Ban " << mask << " has cidr " << this->cidr_len;
}
catch (const ConvertException &) { }
}
}
@@ -822,11 +815,11 @@ Anope::string Entry::GetNUHMask() const
{
case AF_INET:
if (cidr_len <= 32)
c = "/" + stringify(cidr_len);
c = "/" + Anope::ToString(cidr_len);
break;
case AF_INET6:
if (cidr_len <= 128)
c = "/" + stringify(cidr_len);
c = "/" + Anope::ToString(cidr_len);
break;
}