blob: 9f1a9f90b27a1db0893cc18f6e5e390729dbe035 [file] [log] [blame]
Patrick Venture035bbbb2018-12-12 14:59:52 -08001#pragma once
2
3#include <exception>
Patrick Venture9dfcf5d2019-01-16 09:53:10 -08004#include <map>
Patrick Venture035bbbb2018-12-12 14:59:52 -08005#include <sstream>
6#include <string>
7
Patrick Venture9b534f02018-12-13 16:10:02 -08008namespace host_tool
9{
10
Patrick Venture035bbbb2018-12-12 14:59:52 -080011class IpmiException : public std::exception
12{
13 public:
Patrick Venture9dfcf5d2019-01-16 09:53:10 -080014 const std::map<int, std::string> commonFailures = {
15 {0xc0, "busy"},
16 {0xc1, "invalid"},
17 {0xc3, "timeout"},
18 };
19
Patrick Venture035bbbb2018-12-12 14:59:52 -080020 explicit IpmiException(int cc)
21 {
22 std::ostringstream smessage;
Patrick Venture9dfcf5d2019-01-16 09:53:10 -080023
24 auto search = commonFailures.find(cc);
25 if (search != commonFailures.end())
26 {
27 smessage << "Received IPMI_CC: " << search->second;
28 }
29 else
30 {
31 smessage << "Received IPMI_CC: " << cc;
32 }
33
Patrick Venture035bbbb2018-12-12 14:59:52 -080034 message = smessage.str();
35 }
Patrick Ventureecfd3002018-12-14 13:57:28 -080036 explicit IpmiException(const std::string& message) : message(message){};
Patrick Venture035bbbb2018-12-12 14:59:52 -080037
38 virtual const char* what() const noexcept override
39 {
40 return message.c_str();
41 }
42
43 private:
44 std::string message;
45};
Patrick Venture9b534f02018-12-13 16:10:02 -080046
47} // namespace host_tool