]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Clean up CoreException
authorAttila Molnar <attilamolnar@hush.com>
Wed, 18 Dec 2013 15:20:40 +0000 (16:20 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Wed, 18 Dec 2013 15:20:40 +0000 (16:20 +0100)
- Remove default constructor
- Replace virtual functions returning C strings with functions returning const std::string refs

15 files changed:
include/base.h
include/modules.h
src/commands/cmd_dns.cpp
src/commands/cmd_hostname_lookup.cpp
src/helperfuncs.cpp
src/inspsocket.cpp
src/modules/m_cgiirc.cpp
src/modules/m_customprefix.cpp
src/modules/m_dnsbl.cpp
src/modules/m_filter.cpp
src/modules/m_ident.cpp
src/modules/m_rline.cpp
src/modules/m_spanningtree/addline.cpp
src/modules/m_spanningtree/main.cpp
src/usermanager.cpp

index 86aa2769fc3112956b3666a24708637c1720e8dc..ec95342fcd2909882d75c7ab0a828b24ec5eea5c 100644 (file)
@@ -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;
index b7cffd1a080d740ff33c7ffcc18fa93cc815464f..7ceb9f6317c0dfbc3b249f88d2c16ede9c265a22 100644 (file)
@@ -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)
index f9ec8e9900f3e7b6e3f725a5560c698ba7ed4096..07ade381ab3fb94dd5a481173ebaec791104f2b9 100644 (file)
@@ -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;
                }
 
index 3287f3662d228399c87db85e4639e62d5aba26fd..c26d3b3d32fc82e5e5f0d3f756f5436eb3d98642 100644 (file)
@@ -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++;
                }
        }
index 1899ce1b328469791a0c7185ee4ff60601919139..354d0a112e9b2f4354430cbb78e6b87a881e1f68 100644 (file)
@@ -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, ...)
index d7a25785d1d6506f1ca132211cfe8b91a60d83ab..8822f69f82f5538e3aa2f2579a628bfe464538ee 100644 (file)
@@ -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())
index 9e67a4f0882a662f9466976553396640c24f26fc..5dea028fbb787c6b7f7156ee0163f4fee18e6913 100644 (file)
@@ -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());
                }
        }
 
index f0b6d88e340cc4fc77246256768ee801a6f355be..107c6d684b4e0497478e56ed1f417f1e973481a9 100644 (file)
@@ -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() + ")");
                        }
                }
        }
index 48ce1d791ae88c3e0b02429dfc6dde4ebdd0582d..10419de5157e59c674adb9afd2543a8c6096e5d2 100644 (file)
@@ -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)
index 329dd10ff12e7fe5b3dcc0606b52e939b9ae292d..25aa2f97a00261b880200ed9627dc62cc3074b5a 100644 (file)
@@ -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());
                }
        }
 }
index 516287668c9fd7f45426fe127a1dabb05cf23e25..c73e26b16f0fb211451067a19a12e13923d29343 100644 (file)
@@ -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());
                }
        }
 
index 35f88ea93cf6daae26ce804f62bdaa0223acbcb2..2aee89ad282b300053dbbf4aca3adb93a49c94bc 100644 (file)
@@ -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)
index f4485030ae6aa5688c1a0e790f06f90ff76e6c67..c6ca17db07e4abcc515dba022ca56a14daaedc1e 100644 (file)
@@ -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]));
index 75b75f8c045540bab60416473f1c7c717e46bab7..017f1c522e7753154ca091793f06dd537269e151 100644 (file)
@@ -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);
                }
        }
index 1917606863872e9976836a1a0aca2eef64e340ef..1d1a05fa2e269febbaeb993e1a54d396422765ec 100644 (file)
@@ -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());
                }
        }