From 29e7674e56bf2b829bba22def2760d034a76e788 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 11 Mar 2024 13:53:05 +0000 Subject: 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. --- modules/operserv/os_logsearch.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'modules/operserv/os_logsearch.cpp') diff --git a/modules/operserv/os_logsearch.cpp b/modules/operserv/os_logsearch.cpp index 606a74d78..0282644b2 100644 --- a/modules/operserv/os_logsearch.cpp +++ b/modules/operserv/os_logsearch.cpp @@ -47,32 +47,22 @@ public: if (params[i].length() > 2) { Anope::string dur = params[i].substr(1, params[i].length() - 2); - try - { - days = convertTo(dur); - if (days <= 0) - throw ConvertException(); - } - catch (const ConvertException &) - { + auto d = Anope::Convert(dur, 0); + if (d > 0) + days = d; + else source.Reply(_("Invalid duration %s, using %d days."), dur.c_str(), days); - } } break; case 'l': if (params[i].length() > 2) { Anope::string dur = params[i].substr(1, params[i].length() - 2); - try - { - replies = convertTo(dur); - if (replies <= 0) - throw ConvertException(); - } - catch (const ConvertException &) - { + auto r = Anope::Convert(dur, 0); + if (r > 0) + replies = r; + else source.Reply(_("Invalid limit %s, using %d."), dur.c_str(), replies); - } } break; default: -- cgit