master
cpp 36 lines 1.2 KB
Raw
1 // Copyright (C) Microsoft Corporation. All rights reserved.
2 #include <sstream>
3 #include "NetlinkTransactionError.h"
4 #include "NetlinkError.h"
5 #include "NetlinkResponse.h"
6 #include "Utils.h"
7
8 NetlinkTransactionError::NetlinkTransactionError(
9 const std::vector<char>& request, const std::vector<NetlinkResponse>& responses, const std::exception& inner, const std::source_location& source) :
10 RuntimeErrorWithSourceLocation(BuildMessage(request, responses, inner), source)
11 {
12 const auto* error = dynamic_cast<const NetlinkError*>(&inner);
13 if (error != nullptr)
14 {
15 m_error = error->Error();
16 }
17 }
18
19 std::optional<int> NetlinkTransactionError::Error() const
20 {
21 return m_error;
22 }
23
24 std::string NetlinkTransactionError::BuildMessage(const std::vector<char>& request, const std::vector<NetlinkResponse>& responses, const std::exception& inner)
25 {
26 std::stringstream str;
27
28 str << "Error in netlink transaction.\n";
29 str << "Innermost exception: " << inner.what();
30 str << "\nRequest: ";
31 utils::FormatBinary(str, request.data(), request.size());
32 str << "\nResponses: (seen: " << std::to_string(responses.size()) << ") ";
33 utils::FormatArray(str, responses);
34
35 return str.str();
36 }