diff options
-rw-r--r-- | include/modules.h | 34 | ||||
-rw-r--r-- | src/inspircd.cpp | 4 | ||||
-rw-r--r-- | src/inspsocket.cpp | 21 | ||||
-rw-r--r-- | src/socket.cpp | 4 | ||||
-rw-r--r-- | src/userprocess.cpp | 4 | ||||
-rw-r--r-- | src/users.cpp | 12 |
6 files changed, 44 insertions, 35 deletions
diff --git a/include/modules.h b/include/modules.h index ef103a1a5..337064eb3 100644 --- a/include/modules.h +++ b/include/modules.h @@ -117,9 +117,9 @@ typedef std::map<std::string, std::pair<int, modulelist> > interfacelist; { \ ServerInstance->modules[_i]->x ; \ } \ - catch (ModuleException& modexcept) \ + catch (CoreException& modexcept) \ { \ - ServerInstance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason()); \ + ServerInstance->Log(DEFAULT,"Exception cought: %s",modexcept.GetReason()); \ } \ } \ } @@ -131,9 +131,9 @@ typedef std::map<std::string, std::pair<int, modulelist> > interfacelist; { \ z->modules[_i]->x ; \ } \ - catch (ModuleException& modexcept) \ + catch (CoreException& modexcept) \ { \ - z->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason()); \ + z->Log(DEFAULT,"Exception cought: %s",modexcept.GetReason()); \ } \ } \ } @@ -154,9 +154,9 @@ typedef std::map<std::string, std::pair<int, modulelist> > interfacelist; break; \ } \ } \ - catch (ModuleException& modexcept) \ + catch (CoreException& modexcept) \ { \ - ServerInstance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \ + ServerInstance->Log(DEFAULT,"Exception cought: %s",modexcept.GetReason()); \ } \ } \ } \ @@ -175,9 +175,9 @@ typedef std::map<std::string, std::pair<int, modulelist> > interfacelist; break; \ } \ } \ - catch (ModuleException& modexcept) \ + catch (CoreException& modexcept) \ { \ - z->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \ + z->Log(DEBUG,"Exception cought: %s",modexcept.GetReason()); \ } \ } \ } \ @@ -328,13 +328,18 @@ class CoreException : public std::exception /** Holds the error message to be displayed */ const std::string err; + const std::string source; public: /** Default constructor, just uses the error mesage 'Core threw an exception'. */ - CoreException() : err("Core threw an exception") {} + CoreException() : err("Core threw an exception"), source("The core") {} /** This constructor can be used to specify an error message before throwing. */ - CoreException(const std::string &message) : err(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. + */ + 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. * Actually no, it does nothing. Never mind. * @throws Nothing! @@ -347,6 +352,11 @@ class CoreException : public std::exception { return err.c_str(); } + + virtual const char* GetSource() + { + return source.c_str(); + } }; class ModuleException : public CoreException @@ -354,11 +364,11 @@ class ModuleException : public CoreException public: /** Default constructor, just uses the error mesage 'Module threw an exception'. */ - ModuleException() : CoreException("Module threw an exception") {} + ModuleException() : CoreException("Module threw an exception", "A Module") {} /** This constructor can be used to specify an error message before throwing. */ - ModuleException(const std::string &message) : CoreException(message) {} + ModuleException(const std::string &message) : CoreException(message, "A Module") {} /** This destructor solves world hunger, cancels the world debt, and causes the world to end. * Actually no, it does nothing. Never mind. * @throws Nothing! diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 59be29843..54c3aa0ab 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -653,10 +653,10 @@ bool InspIRCd::LoadModule(const char* filename) return false; } } - catch (ModuleException& modexcept) + catch (CoreException& modexcept) { this->Log(DEFAULT,"Unable to load %s: ",modfile,modexcept.GetReason()); - snprintf(MODERR,MAXBUF,"Factory function threw an exception: %s",modexcept.GetReason()); + snprintf(MODERR,MAXBUF,"Factory function of %s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); return false; } } diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 34f4a6201..68e2c8f96 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -262,9 +262,9 @@ void InspSocket::Close() { Instance->Config->GetIOHook(this)->OnRawSocketClose(this->fd); } - catch (ModuleException& modexcept) + catch (CoreException& modexcept) { - Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); + Instance->Log(DEFAULT,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); } } this->OnClose(); @@ -293,9 +293,9 @@ char* InspSocket::Read() { MOD_RESULT = Instance->Config->GetIOHook(this)->OnRawSocketRead(this->fd,this->ibuf,sizeof(this->ibuf),result2); } - catch (ModuleException& modexcept) + catch (CoreException& modexcept) { - Instance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason()); + Instance->Log(DEFAULT,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); } if (MOD_RESULT < 0) { @@ -397,9 +397,9 @@ bool InspSocket::FlushWriteBuffer() return true; } } - catch (ModuleException& modexcept) + catch (CoreException& modexcept) { - Instance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason()); + Instance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); return true; } } @@ -517,9 +517,9 @@ bool InspSocket::Poll() { Instance->Config->GetIOHook(this)->OnRawSocketConnect(this->fd); } - catch (ModuleException& modexcept) + catch (CoreException& modexcept) { - Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); + Instance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); } } return this->OnConnected(); @@ -544,9 +544,9 @@ bool InspSocket::Poll() Instance->Config->GetIOHook(this)->OnRawSocketAccept(incoming, insp_ntoa(client.sin_addr), this->port); #endif } - catch (ModuleException& modexcept) + catch (CoreException& modexcept) { - Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); + Instance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); } } @@ -637,7 +637,6 @@ void InspSocket::HandleEvent(EventType et, int errornum) } else { - Instance->Log(DEBUG,"State=%d CONNECTED=%d", this->state, I_CONNECTED); if (this->FlushWriteBuffer()) { this->Instance->SE->DelFd(this); diff --git a/src/socket.cpp b/src/socket.cpp index 6883e05fd..b286ee96f 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -80,9 +80,9 @@ void ListenSocket::HandleEvent(EventType et, int errornum) ServerInstance->Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, insp_ntoa(client.sin_addr), in_port); #endif } - catch (ModuleException& modexcept) + catch (CoreException& modexcept) { - ServerInstance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); + ServerInstance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); } } ServerInstance->stats->statsAccept++; diff --git a/src/userprocess.cpp b/src/userprocess.cpp index 1e21c065d..a740d0d7c 100644 --- a/src/userprocess.cpp +++ b/src/userprocess.cpp @@ -37,9 +37,9 @@ void InspIRCd::ProcessUser(userrec* cu) { MOD_RESULT = this->Config->GetIOHook(cu->GetPort())->OnRawSocketRead(cu->GetFd(),ReadBuffer,sizeof(ReadBuffer),result2); } - catch (ModuleException& modexcept) + catch (CoreException& modexcept) { - this->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason()); + this->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); } if (MOD_RESULT < 0) diff --git a/src/users.cpp b/src/users.cpp index 1abbcc37a..4a77b450f 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -153,7 +153,7 @@ void userrec::StartDNSLookup() res_reverse = new UserResolver(this->ServerInstance, this, this->GetIPString(), DNS_QUERY_REVERSE); this->ServerInstance->AddResolver(res_reverse); } - catch (ModuleException& e) + catch (CoreException& e) { ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason()); } @@ -186,7 +186,7 @@ void UserResolver::OnLookupComplete(const std::string &result) this->ServerInstance->AddResolver(bound_user->res_forward); } } - catch (ModuleException& e) + catch (CoreException& e) { ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason()); } @@ -791,9 +791,9 @@ void userrec::QuitUser(InspIRCd* Instance, userrec *user, const std::string &qui { Instance->Config->GetIOHook(user->GetPort())->OnRawSocketClose(user->fd); } - catch (ModuleException& modexcept) + catch (CoreException& modexcept) { - Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); + Instance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); } } @@ -1445,9 +1445,9 @@ void userrec::Write(std::string text) { ServerInstance->Config->GetIOHook(this->GetPort())->OnRawSocketWrite(this->fd, text.data(), text.length()); } - catch (ModuleException& modexcept) + catch (CoreException& modexcept) { - ServerInstance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason()); + ServerInstance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); } } else |