summaryrefslogtreecommitdiffstats
path: root/src/ipmiblob/ipmi_errors.hpp
blob: 15a5d4c5183a33a0d0f0c3837febb79dbbbe8d4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#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
OpenPOWER on IntegriCloud