blob: b17db3d4696a53b6744dabf052a7c3b82f3f5f12 [file] [log] [blame]
#pragma once
#include <exception>
#include <map>
#include <string>
namespace ipmiblob
{
class IpmiException : public std::exception
{
public:
IpmiException(const std::string& message, int code) :
_message(message), _ccode(code){};
static std::string messageFromIpmi(int cc)
{
const std::map<int, std::string> commonFailures = {
{0xc0, "busy"},
{0xc1, "invalid"},
{0xc3, "timeout"},
};
auto search = commonFailures.find(cc);
if (search != commonFailures.end())
{
return "Received IPMI_CC: " + search->second;
}
else
{
return "Received IPMI_CC: " + std::to_string(cc);
}
}
/* This will leave the code as 0, but by virtue of being an exception
* thrown, we'll know it was an error on the host-side.
*/
explicit IpmiException(const std::string& message) : _message(message) {}
explicit IpmiException(int cc) : IpmiException(messageFromIpmi(cc), cc) {}
virtual const char* what() const noexcept override
{
return _message.c_str();
}
int code() const noexcept
{
return _ccode;
}
private:
std::string _message;
int _ccode = 0;
};
} // namespace ipmiblob