The complete source code of IdealIRC http://www.idealirc.org/
 
 
 
 
idealirc/IRCClient/IRCError.cpp

105 lines
3.2 KiB

#include "IRCError.h"
#include <iostream>
#include <fmt/format.h>
#include <asio/error.hpp>
std::string IRCErrorToString(IRCError e)
{
switch (e) {
case IRCError::NoError:
return "No error";
case IRCError::NotConnected:
return "Not connected";
case IRCError::AlreadyConnected:
return "Already connected";
case IRCError::CannotResolveAddress:
return "Cannot resolve address";
case IRCError::BrokenPipe:
return "Broken pipe";
case IRCError::ConnectionAborted:
return "Connection aborted";
case IRCError::ConnectionRefused:
return "Connection refused";
case IRCError::ConnectionReset:
return "Connection reset";
case IRCError::HostUnreachable:
return "Host unreachable";
case IRCError::NetworkDown:
return "Network down";
case IRCError::NetworkReset:
return "Network reset";
case IRCError::NetworkUnreachable:
return "Network unreachable";
case IRCError::NoDescriptors:
return "No file descriptors left";
case IRCError::TimedOut:
return "Timed out";
case IRCError::EndOfFile:
return "EOF";
case IRCError::SSL_SelfSigned:
return "SSL: Self-signed certificate";
case IRCError::SSL_CN_Mismatch:
return "SSL: (CN) Hostname mismatch";
case IRCError::SSL_CN_Missing:
return "SSL: (CN) Hostname missing";
case IRCError::SSL_CN_WildcardIllegal:
return "SSL: (CN) Illegal wildcard usage";
case IRCError::SSL_NotYetValid:
return "SSL: Certificate not yet valid";
case IRCError::SSL_Expired:
return "SSL: Certificate expired";
case IRCError::CannotChangeWhenConnected:
return "Cannot change this setting when connected";
case IRCError::HostNotSet:
return "Hostname is not set";
case IRCError::PortNotSet:
return "Port number is not set";
case IRCError::IdentNotSet:
return "Ident/username is not set";
case IRCError::NicknameNotSet:
return "Nickname is not set";
case IRCError::RealnameNotSet:
return "Real name is not set";
case IRCError::DCC_NotATarget:
return "DCC: We are not a DCC target";
case IRCError::DCC_TimedOut:
return "DCC: Request timed out";
case IRCError::UnhandledException:
return "Unhandled exception";
}
}
IRCError SystemErrorToIRCError(const std::system_error& e)
{
switch (e.code().value()) {
case 0:
return IRCError::NoError;
case asio::error::host_not_found:
return IRCError::CannotResolveAddress;
case asio::error::broken_pipe:
return IRCError::BrokenPipe;
case asio::error::connection_aborted:
return IRCError::ConnectionAborted;
case asio::error::connection_refused:
return IRCError::ConnectionRefused;
case asio::error::connection_reset:
return IRCError::ConnectionReset;
case asio::error::host_unreachable:
return IRCError::HostUnreachable;
case asio::error::network_down:
return IRCError::NetworkDown;
case asio::error::network_reset:
return IRCError::NetworkReset;
case asio::error::network_unreachable:
return IRCError::NetworkUnreachable;
case asio::error::no_descriptors:
return IRCError::NoDescriptors;
case asio::error::timed_out:
return IRCError::TimedOut;
case asio::error::eof:
return IRCError::EndOfFile;
default:
std::cerr << fmt::format("Unhandled exception {}: {}", e.code().value(), e.code().message()) << std::endl;
return IRCError::UnhandledException;
}
}