diff options
author | Sadie Powell <sadie@witchery.services> | 2024-03-11 13:53:05 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-03-11 19:17:29 +0000 |
commit | 29e7674e56bf2b829bba22def2760d034a76e788 (patch) | |
tree | f40049ba995b03dd7c510d88f9f19db2d2e65a2e /modules/chanserv/cs_access.cpp | |
parent | e2df7d4d01f8fdb41c49ce8efc462cab005e7d5c (diff) |
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.
Diffstat (limited to 'modules/chanserv/cs_access.cpp')
-rw-r--r-- | modules/chanserv/cs_access.cpp | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/modules/chanserv/cs_access.cpp b/modules/chanserv/cs_access.cpp index 3d2c3c8d6..f86d9f5bc 100644 --- a/modules/chanserv/cs_access.cpp +++ b/modules/chanserv/cs_access.cpp @@ -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); } |