-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from microsoft/strongexcepttype
Signal netlink errors with exceptions
- Loading branch information
Showing
16 changed files
with
264 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
#include <stdexcept> | ||
#include <string> | ||
#include <system_error> | ||
|
||
#include <microsoft/net/netlink/NetlinkErrorCategory.hxx> | ||
#include <netlink/errno.h> | ||
|
||
namespace Microsoft::Net::Netlink | ||
{ | ||
|
||
const char* | ||
NetlinkErrorCategory::name() const noexcept | ||
{ | ||
static constexpr const char* Name = "Netlink"; | ||
return Name; | ||
} | ||
|
||
std::string | ||
NetlinkErrorCategory::message(int error) const | ||
{ | ||
return nl_geterror(error); | ||
} | ||
|
||
std::error_condition | ||
NetlinkErrorCategory::default_error_condition(int error) const noexcept | ||
{ | ||
return std::error_condition(error, *this); | ||
} | ||
|
||
std::error_code | ||
make_netlink_error_code(int error) | ||
{ | ||
return std::error_code(error, NetlinkErrorCategory()); | ||
} | ||
|
||
std::error_code | ||
MakeNetlinkErrorCode(int error) | ||
{ | ||
if (error < 0) { | ||
throw std::runtime_error("Netlink error codes must be non-negative; this is a programming error"); | ||
} | ||
|
||
return make_netlink_error_code(error); | ||
} | ||
|
||
} // namespace Microsoft::Net::Netlink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
#include <format> | ||
#include <string> | ||
#include <system_error> | ||
|
||
#include <microsoft/net/netlink/NetlinkErrorCategory.hxx> | ||
#include <microsoft/net/netlink/NetlinkException.hxx> | ||
#include <plog/Log.h> | ||
|
||
using namespace Microsoft::Net::Netlink; | ||
|
||
NetlinkException::NetlinkException(int error, const char *what) : | ||
std::system_error(MakeNetlinkErrorCode(error), what) | ||
{} | ||
|
||
NetlinkException::NetlinkException(int error, const std::string &what) : | ||
NetlinkException(error, what.c_str()) | ||
{} | ||
|
||
/* static */ | ||
NetlinkException | ||
NetlinkException::CreateLogged(int error, const char *what) | ||
{ | ||
NetlinkException netlinkException(error, what); | ||
LOGE << std::format("Netlink error ({}): {} ({})", netlinkException.code().value(), netlinkException.what(), netlinkException.code().message()); | ||
return netlinkException; | ||
} | ||
|
||
/* static */ | ||
NetlinkException | ||
NetlinkException::CreateLogged(int error, const std::string &what) | ||
{ | ||
return CreateLogged(error, what.c_str()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.