summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2013-12-18 16:20:40 +0100
committerAttila Molnar <attilamolnar@hush.com>2013-12-18 16:20:40 +0100
commit1e8389b27ff99ad9f48c890486ebef936acafc41 (patch)
tree44543c79a89509604d2fa7b910c278476b9a0eba
parent0680b529874b701b20650586d8466a155d9ba0d5 (diff)
Clean up CoreException
- Remove default constructor - Replace virtual functions returning C strings with functions returning const std::string refs
-rw-r--r--include/base.h25
-rw-r--r--include/modules.h4
-rw-r--r--src/commands/cmd_dns.cpp2
-rw-r--r--src/commands/cmd_hostname_lookup.cpp4
-rw-r--r--src/helperfuncs.cpp4
-rw-r--r--src/inspsocket.cpp8
-rw-r--r--src/modules/m_cgiirc.cpp2
-rw-r--r--src/modules/m_customprefix.cpp2
-rw-r--r--src/modules/m_dnsbl.cpp2
-rw-r--r--src/modules/m_filter.cpp6
-rw-r--r--src/modules/m_ident.cpp2
-rw-r--r--src/modules/m_rline.cpp2
-rw-r--r--src/modules/m_spanningtree/addline.cpp2
-rw-r--r--src/modules/m_spanningtree/main.cpp2
-rw-r--r--src/usermanager.cpp2
15 files changed, 34 insertions, 35 deletions
diff --git a/include/base.h b/include/base.h
index 86aa2769f..ec95342fc 100644
--- a/include/base.h
+++ b/include/base.h
@@ -179,21 +179,23 @@ class reference
*/
class CoreExport CoreException : public std::exception
{
- public:
+ protected:
/** Holds the error message to be displayed
*/
const std::string err;
/** Source of the exception
*/
const std::string source;
- /** Default constructor, just uses the error mesage 'Core threw an exception'.
- */
- CoreException() : err("Core threw an exception"), source("The core") {}
+
+ public:
/** This constructor can be used to specify an error message before throwing.
+ * @param message Human readable error message
*/
CoreException(const std::string &message) : err(message), source("The core") {}
/** This constructor can be used to specify an error message before throwing,
* and to specify the source of the exception.
+ * @param message Human readable error message
+ * @param src Source of the exception
*/
CoreException(const std::string &message, const std::string &src) : err(message), source(src) {}
/** This destructor solves world hunger, cancels the world debt, and causes the world to end.
@@ -202,17 +204,14 @@ class CoreExport CoreException : public std::exception
*/
virtual ~CoreException() throw() {};
/** Returns the reason for the exception.
- * The module should probably put something informative here as the user will see this upon failure.
+ * @return Human readable description of the error
*/
- virtual const char* GetReason()
- {
- return err.c_str();
- }
+ const std::string& GetReason() const { return err; }
- virtual const char* GetSource()
- {
- return source.c_str();
- }
+ /** Returns the source of the exception
+ * @return Source of the exception
+ */
+ const std::string& GetSource() const { return source; }
};
class Module;
diff --git a/include/modules.h b/include/modules.h
index b7cffd1a0..7ceb9f631 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -132,7 +132,7 @@ struct ModResult {
} \
catch (CoreException& modexcept) \
{ \
- ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Exception caught: %s",modexcept.GetReason()); \
+ ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Exception caught: " + modexcept.GetReason()); \
} \
} \
} while (0);
@@ -157,7 +157,7 @@ do { \
} \
catch (CoreException& except_ ## n) \
{ \
- ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Exception caught: %s", (except_ ## n).GetReason()); \
+ ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Exception caught: " + (except_ ## n).GetReason()); \
} \
} \
} while(0)
diff --git a/src/commands/cmd_dns.cpp b/src/commands/cmd_dns.cpp
index f9ec8e990..07ade381a 100644
--- a/src/commands/cmd_dns.cpp
+++ b/src/commands/cmd_dns.cpp
@@ -580,7 +580,7 @@ class MyManager : public Manager, public Timer, public EventHandler
}
catch (Exception& ex)
{
- ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, std::string(ex.GetReason()));
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, ex.GetReason());
return;
}
diff --git a/src/commands/cmd_hostname_lookup.cpp b/src/commands/cmd_hostname_lookup.cpp
index 3287f3662..c26d3b3d3 100644
--- a/src/commands/cmd_hostname_lookup.cpp
+++ b/src/commands/cmd_hostname_lookup.cpp
@@ -92,7 +92,7 @@ class UserResolver : public DNS::Request
catch (DNS::Exception& e)
{
delete res_forward;
- ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Error in resolver: %s",e.GetReason());
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Error in resolver: " + e.GetReason());
bound_user->WriteNotice("*** There was an internal error resolving your host, using your IP address (" + bound_user->GetIPString() + ") instead.");
dl->set(bound_user, 0);
@@ -214,7 +214,7 @@ class ModuleHostnameLookup : public Module
{
this->dnsLookup.set(user, 0);
delete res_reverse;
- ServerInstance->Logs->Log("USERS", LOG_DEBUG, "Error in resolver: %s", e.GetReason());
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Error in resolver: " + e.GetReason());
ServerInstance->stats->statsDnsBad++;
}
}
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 1899ce1b3..354d0a112 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -404,13 +404,13 @@ const char* InspIRCd::Format(va_list &vaList, const char* formatString)
if (vsnret > 0 && static_cast<unsigned>(vsnret) < formatBuffer.size())
{
- return &formatBuffer[0];
+ break;
}
formatBuffer.resize(formatBuffer.size() * 2);
}
- throw CoreException();
+ return &formatBuffer[0];
}
const char* InspIRCd::Format(const char* formatString, ...)
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp
index d7a25785d..8822f69f8 100644
--- a/src/inspsocket.cpp
+++ b/src/inspsocket.cpp
@@ -132,7 +132,7 @@ void StreamSocket::Close()
catch (CoreException& modexcept)
{
ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "%s threw an exception: %s",
- modexcept.GetSource(), modexcept.GetReason());
+ modexcept.GetSource().c_str(), modexcept.GetReason().c_str());
}
DelIOHook();
}
@@ -172,7 +172,7 @@ void StreamSocket::DoRead()
catch (CoreException& modexcept)
{
ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "%s threw an exception: %s",
- modexcept.GetSource(), modexcept.GetReason());
+ modexcept.GetSource().c_str(), modexcept.GetReason().c_str());
return;
}
if (rv > 0)
@@ -321,7 +321,7 @@ void StreamSocket::DoWrite()
catch (CoreException& modexcept)
{
ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "%s threw an exception: %s",
- modexcept.GetSource(), modexcept.GetReason());
+ modexcept.GetSource().c_str(), modexcept.GetReason().c_str());
}
}
#ifndef DISABLE_WRITEV
@@ -533,7 +533,7 @@ void StreamSocket::HandleEvent(EventType et, int errornum)
catch (CoreException& ex)
{
ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Caught exception in socket processing on FD %d - '%s'",
- fd, ex.GetReason());
+ fd, ex.GetReason().c_str());
SetError(ex.GetReason());
}
if (!error.empty())
diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp
index 9e67a4f08..5dea028fb 100644
--- a/src/modules/m_cgiirc.cpp
+++ b/src/modules/m_cgiirc.cpp
@@ -222,7 +222,7 @@ class ModuleCgiIRC : public Module
waiting.set(user, count - 1);
delete r;
if (cmd.notify)
- ServerInstance->SNO->WriteToSnoMask('a', "Connecting user %s detected as using CGI:IRC (%s), but I could not resolve their hostname; %s", user->nick.c_str(), user->host.c_str(), ex.GetReason());
+ ServerInstance->SNO->WriteToSnoMask('a', "Connecting user %s detected as using CGI:IRC (%s), but I could not resolve their hostname; %s", user->nick.c_str(), user->host.c_str(), ex.GetReason().c_str());
}
}
diff --git a/src/modules/m_customprefix.cpp b/src/modules/m_customprefix.cpp
index f0b6d88e3..107c6d684 100644
--- a/src/modules/m_customprefix.cpp
+++ b/src/modules/m_customprefix.cpp
@@ -69,7 +69,7 @@ class ModuleCustomPrefix : public Module
}
catch (ModuleException& e)
{
- throw ModuleException(e.err + " (while creating mode from " + tag->getTagLocation() + ")");
+ throw ModuleException(e.GetReason() + " (while creating mode from " + tag->getTagLocation() + ")");
}
}
}
diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp
index 48ce1d791..10419de51 100644
--- a/src/modules/m_dnsbl.cpp
+++ b/src/modules/m_dnsbl.cpp
@@ -346,7 +346,7 @@ class ModuleDNSBL : public Module
catch (DNS::Exception &ex)
{
delete r;
- ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, std::string(ex.GetReason()));
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, ex.GetReason());
}
if (user->quitting)
diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp
index 329dd10ff..25aa2f97a 100644
--- a/src/modules/m_filter.cpp
+++ b/src/modules/m_filter.cpp
@@ -551,7 +551,7 @@ void ModuleFilter::OnDecodeMetaData(Extensible* target, const std::string &extna
}
catch (ModuleException& e)
{
- ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Error when unserializing filter: " + std::string(e.GetReason()));
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Error when unserializing filter: " + e.GetReason());
}
}
}
@@ -619,7 +619,7 @@ std::pair<bool, std::string> ModuleFilter::AddFilter(const std::string &freeform
}
catch (ModuleException &e)
{
- ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Error in regular expression '%s': %s", freeform.c_str(), e.GetReason());
+ ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Error in regular expression '%s': %s", freeform.c_str(), e.GetReason().c_str());
return std::make_pair(false, e.GetReason());
}
return std::make_pair(true, "");
@@ -683,7 +683,7 @@ void ModuleFilter::ReadFilters()
}
catch (ModuleException &e)
{
- ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Error in regular expression '%s': %s", pattern.c_str(), e.GetReason());
+ ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Error in regular expression '%s': %s", pattern.c_str(), e.GetReason().c_str());
}
}
}
diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp
index 516287668..c73e26b16 100644
--- a/src/modules/m_ident.cpp
+++ b/src/modules/m_ident.cpp
@@ -303,7 +303,7 @@ class ModuleIdent : public Module
}
catch (ModuleException &e)
{
- ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Ident exception: %s", e.GetReason());
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Ident exception: " + e.GetReason());
}
}
diff --git a/src/modules/m_rline.cpp b/src/modules/m_rline.cpp
index 35f88ea93..2aee89ad2 100644
--- a/src/modules/m_rline.cpp
+++ b/src/modules/m_rline.cpp
@@ -154,7 +154,7 @@ class CommandRLine : public Command
}
catch (ModuleException &e)
{
- ServerInstance->SNO->WriteToSnoMask('a',"Could not add RLINE: %s", e.GetReason());
+ ServerInstance->SNO->WriteToSnoMask('a',"Could not add RLINE: " + e.GetReason());
}
if (r)
diff --git a/src/modules/m_spanningtree/addline.cpp b/src/modules/m_spanningtree/addline.cpp
index f4485030a..c6ca17db0 100644
--- a/src/modules/m_spanningtree/addline.cpp
+++ b/src/modules/m_spanningtree/addline.cpp
@@ -42,7 +42,7 @@ CmdResult CommandAddLine::Handle(User* usr, std::vector<std::string>& params)
}
catch (ModuleException &e)
{
- ServerInstance->SNO->WriteToSnoMask('d',"Unable to ADDLINE type %s from %s: %s", params[0].c_str(), setter.c_str(), e.GetReason());
+ ServerInstance->SNO->WriteToSnoMask('d',"Unable to ADDLINE type %s from %s: %s", params[0].c_str(), setter.c_str(), e.GetReason().c_str());
return CMD_FAILURE;
}
xl->SetCreateTime(ConvToInt(params[3]));
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp
index 75b75f8c0..017f1c522 100644
--- a/src/modules/m_spanningtree/main.cpp
+++ b/src/modules/m_spanningtree/main.cpp
@@ -280,7 +280,7 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y)
catch (DNS::Exception& e)
{
delete snr;
- ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(), e.GetReason());
+ ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(), e.GetReason().c_str());
ConnectServer(y, false);
}
}
diff --git a/src/usermanager.cpp b/src/usermanager.cpp
index 191760686..1d1a05fa2 100644
--- a/src/usermanager.cpp
+++ b/src/usermanager.cpp
@@ -73,7 +73,7 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs
}
catch (CoreException& modexcept)
{
- ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
+ ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "%s threw an exception: %s", modexcept.GetSource().c_str(), modexcept.GetReason().c_str());
}
}