blob: 9f1a9f90b27a1db0893cc18f6e5e390729dbe035 [file] [log] [blame]
Patrick Venture123b5c02019-03-05 14:01:00 -08001#pragma once
2
3#include <exception>
4#include <map>
5#include <sstream>
6#include <string>
7
8namespace host_tool
9{
10
11class IpmiException : public std::exception
12{
13 public:
14 const std::map<int, std::string> commonFailures = {
15 {0xc0, "busy"},
16 {0xc1, "invalid"},
17 {0xc3, "timeout"},
18 };
19
20 explicit IpmiException(int cc)
21 {
22 std::ostringstream smessage;
23
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
34 message = smessage.str();
35 }
36 explicit IpmiException(const std::string& message) : message(message){};
37
38 virtual const char* what() const noexcept override
39 {
40 return message.c_str();
41 }
42
43 private:
44 std::string message;
45};
46
47} // namespace host_tool