virthttp  0.0
libvirt http interface
error_msg.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <array>
3 #include <string_view>
4 #include "cexpr_algs.hpp"
5 
6 using namespace std::literals;
7 
12  using P = std::pair<int, std::string_view>;
17  constexpr static std::array pairs = {
18  P{-1, "Unsupported"sv},
19  P{0, "Syntax error"sv},
20  P{1, "Bad X-Auth-Key"sv},
21  P{2, "Bad URL"sv},
22  P{3, "Bad request"sv},
23  P{4, "No subsystem"sv},
24  P{5, "Bad subsystem"sv},
25  P{6, "Subsystem requires parameters"},
26  P{7, "Bad subsystem parameter"},
27  P{10, "Failed to open connection to the libvirt daemon"sv},
28  P{100, "Bad object identifier"sv},
29  P{101, "Invalid search key"sv},
30  P{102, "Search flag doesn't exist"sv},
31  P{105, "Failed to create domain"sv},
32  P{122, "Bad action"sv},
33  P{123, "Unknown action"sv},
34  P{200, "Could not shut down the domain"sv},
35  P{201, "Domain is not running"sv},
36  P{202, "Could not start the domain"sv},
37  P{203, "Domain is already active"sv},
38  P{204, "No status actions specified"sv},
39  P{205, "Renaming failed"sv},
40  P{206, "Setting available memory failed"sv},
41  P{207, "Setting maximum available memory failed"sv},
42  P{208, "Setting autostart policy failed"sv},
43  P{209, "Could not destroy the domain"sv},
44  P{210, "Domain is not active"sv},
45  P{211, "Domain is not suspended"sv},
46  P{212, "Cannot resume the domain"sv},
47  P{213, "Cannot reboot the domain"sv},
48  P{214, "Cannot reset the domain"sv},
49  P{215, "Cannot suspend the domain"sv},
50  P{216, "Cannot delete the domain"sv},
51  P{298, "PATCH data has to be an array of actions"sv},
52  P{300, "Invalid power management value"sv},
53  P{301, "Invalid flag"sv},
54  P{500, "Error occurred while getting network status"sv},
55  P{503, "Error occurred while getting network autostart"sv},
56  };
57 
58  public:
66  constexpr auto operator[](int errc) const noexcept -> std::string_view {
67  const auto* const it = cexpr::find_if(pairs.begin(), pairs.end(), [=](auto p) { return p.first == errc; });
68  return it != pairs.end() ? it->second : "Unknown error"sv;
69  }
70 } constexpr inline static error_messages;
Definition: error_msg.hpp:11
class ErrorMessages error_messages
constexpr auto operator[](int errc) const noexcept-> std::string_view
Definition: error_msg.hpp:66
constexpr InputIt find_if(InputIt first, InputIt last, UnaryPredicate p)
Definition: cexpr_algs.hpp:12