1
0
mirror of https://github.com/anope/anope.git synced 2026-07-04 23:33:12 +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
+12 -21
View File
@@ -37,18 +37,13 @@ public:
Anope::string AccessSerialize() const override
{
return stringify(this->level);
return Anope::ToString(this->level);
}
void AccessUnserialize(const Anope::string &data) override
{
try
{
this->level = convertTo<int>(data);
}
catch (const ConvertException &)
{
}
if (auto l = Anope::TryConvert<int>(data))
this->level = l.value();
}
bool operator>(const ChanAccess &other) const override
@@ -95,11 +90,9 @@ class CommandCSAccess final
Privilege *p = NULL;
int level = ACCESS_INVALID;
try
{
level = convertTo<int>(params[3]);
}
catch (const ConvertException &)
if (auto lvl = Anope::TryConvert<int>(params[3]))
level = lvl.value();
else
{
p = PrivilegeManager::FindPrivilege(params[3]);
if (p != NULL && defaultLevels[p->name])
@@ -402,7 +395,7 @@ class CommandCSAccess final
}
ListFormatter::ListEntry entry;
entry["Number"] = stringify(number);
entry["Number"] = Anope::ToString(number);
entry["Level"] = access->AccessSerialize();
entry["Mask"] = access->Mask();
entry["By"] = access->creator;
@@ -442,7 +435,7 @@ class CommandCSAccess final
}
ListFormatter::ListEntry entry;
entry["Number"] = stringify(i + 1);
entry["Number"] = Anope::ToString(i + 1);
entry["Level"] = access->AccessSerialize();
entry["Mask"] = access->Mask();
entry["By"] = access->creator;
@@ -652,11 +645,9 @@ class CommandCSLevels final
level = ACCESS_FOUNDER;
else
{
try
{
level = convertTo<int>(lev);
}
catch (const ConvertException &)
if (auto lvl = Anope::TryConvert<int>(lev))
level = lvl.value();
else
{
this->OnSyntaxError(source, "SET");
return;
@@ -734,7 +725,7 @@ class CommandCSLevels final
else if (j == ACCESS_FOUNDER)
entry["Level"] = Language::Translate(source.GetAccount(), _("(founder only)"));
else
entry["Level"] = stringify(j);
entry["Level"] = Anope::ToString(j);
list.AddEntry(entry);
}