diff options
| author | Lexi Winter <lexi@hemlock.eden.le-fay.org> | 2025-03-29 04:42:19 +0000 |
|---|---|---|
| committer | Lexi Winter <lexi@hemlock.eden.le-fay.org> | 2025-03-29 04:42:19 +0000 |
| commit | 249a5b6421098ccaa6d269afac2b0ee67f389860 (patch) | |
| tree | 0f52a15d15df13bf111dc41509ab2ddf2e12d7c5 | |
| parent | fdcef3e5582466785811446acda21cd1b4b76efd (diff) | |
| download | libnvxx-249a5b6421098ccaa6d269afac2b0ee67f389860.tar.gz libnvxx-249a5b6421098ccaa6d269afac2b0ee67f389860.tar.bz2 | |
change set_error() to take an std::errc
| -rw-r--r-- | libnvxx/nv_list.cc | 4 | ||||
| -rw-r--r-- | libnvxx/nvxx.3 | 7 | ||||
| -rw-r--r-- | libnvxx/nvxx_base.h | 2 | ||||
| -rw-r--r-- | libnvxx/tests/nvxx_basic.cc | 30 |
4 files changed, 25 insertions, 18 deletions
diff --git a/libnvxx/nv_list.cc b/libnvxx/nv_list.cc index 8f868d9..3d8c0a1 100644 --- a/libnvxx/nv_list.cc +++ b/libnvxx/nv_list.cc @@ -142,12 +142,12 @@ namespace __detail { */ void -__nv_list::set_error(int error) +__nv_list::set_error(std::errc error) { __throw_if_null(); // nvlist does not allow changing an existing error state __throw_if_error(); - ::nvlist_set_error(__m_nv, error); + ::nvlist_set_error(__m_nv, static_cast<int>(error)); } __nv_list::operator const_nv_list() const diff --git a/libnvxx/nvxx.3 b/libnvxx/nvxx.3 index 4cdfea4..ed3dfae 100644 --- a/libnvxx/nvxx.3 +++ b/libnvxx/nvxx.3 @@ -128,7 +128,7 @@ struct nv_list : <unspecified> { ::nvlist_t *release() &&; - void set_error(int error); + void set_error(std::errc error); void free(std::string_view name); @@ -595,6 +595,11 @@ is equal to .Vt T . .Sh NV_LIST OPERATIONS The +.Fn set_error +member function sets the given error on the nvlist, placing it in the error +state. +.Pp +The .Fn add_null , .Fn add_bool , .Fn add_number , diff --git a/libnvxx/nvxx_base.h b/libnvxx/nvxx_base.h index 0f6b254..257c217 100644 --- a/libnvxx/nvxx_base.h +++ b/libnvxx/nvxx_base.h @@ -205,7 +205,7 @@ struct __nv_list : virtual __nv_list_base { /* * Set the error code on this nvlist to the given value. */ - void set_error(int); + void set_error(std::errc); /* * Convert this nv_list into a const_nv_list. This is a shallow copy diff --git a/libnvxx/tests/nvxx_basic.cc b/libnvxx/tests/nvxx_basic.cc index 7638a0b..a552ad1 100644 --- a/libnvxx/tests/nvxx_basic.cc +++ b/libnvxx/tests/nvxx_basic.cc @@ -37,10 +37,11 @@ TEST_CASE(nvxx_set_error) auto nvl = bsd::nv_list(); ATF_REQUIRE_EQ(true, !nvl.error()); - nvl.set_error(EINVAL); + nvl.set_error(std::errc::invalid_argument); ATF_REQUIRE_EQ(true, (nvl.error() == std::errc::invalid_argument)); - ATF_REQUIRE_THROW(bsd::nv_error_state, nvl.set_error(EEXIST)); + ATF_REQUIRE_THROW(bsd::nv_error_state, + nvl.set_error(std::errc::invalid_argument)); } TEST_CASE(nvxx_error_null) @@ -56,7 +57,8 @@ TEST_CASE(nvxx_set_error_null) auto nvl = bsd::nv_list(); auto nvl2 = std::move(nvl); - ATF_REQUIRE_THROW(std::logic_error, nvl.set_error(EINVAL)); + ATF_REQUIRE_THROW(std::logic_error, + nvl.set_error(std::errc::invalid_argument)); } /* @@ -203,7 +205,7 @@ TEST_CASE(nvxx_add_null_error) auto constexpr key = "test_null"sv; auto nvl = bsd::nv_list(); - nvl.set_error(EINVAL); + nvl.set_error(std::errc::invalid_argument); ATF_REQUIRE_THROW(bsd::nv_error_state, nvl.add_null(key)); } @@ -296,7 +298,7 @@ TEST_CASE(nvxx_add_bool_error) auto constexpr value = true; auto nvl = bsd::nv_list(); - nvl.set_error(EINVAL); + nvl.set_error(std::errc::invalid_argument); ATF_REQUIRE_THROW(bsd::nv_error_state, nvl.add_bool(key, value)); } @@ -421,7 +423,7 @@ TEST_CASE(nvxx_add_bool_array_error) auto value = std::vector<bool>{true, false}; auto nvl = bsd::nv_list(); - nvl.set_error(EINVAL); + nvl.set_error(std::errc::invalid_argument); ATF_REQUIRE_THROW(bsd::nv_error_state, nvl.add_bool_range(key, value)); } @@ -558,7 +560,7 @@ TEST_CASE(nvxx_add_number_error) auto constexpr value = 42_u64; auto nvl = bsd::nv_list(); - nvl.set_error(EINVAL); + nvl.set_error(std::errc::invalid_argument); ATF_REQUIRE_THROW(bsd::nv_error_state, nvl.add_number(key, value)); } @@ -684,7 +686,7 @@ TEST_CASE(nvxx_add_number_array_error) auto value = std::vector<std::uint64_t>{42, 666}; auto nvl = bsd::nv_list(); - nvl.set_error(EINVAL); + nvl.set_error(std::errc::invalid_argument); ATF_REQUIRE_THROW(bsd::nv_error_state, nvl.add_number_range(key, value)); } @@ -946,7 +948,7 @@ TEST_CASE(nvxx_add_string_error) auto constexpr value = "test"sv; auto nvl = bsd::nv_list{}; - nvl.set_error(EINVAL); + nvl.set_error(std::errc::invalid_argument); ATF_REQUIRE_THROW(bsd::nv_error_state, nvl.add_string(key, value)); } @@ -957,7 +959,7 @@ TEST_CASE(nvxx_add_string_array_error) auto values = std::vector{"one"sv, "two"sv, "three"sv}; auto nvl = bsd::nv_list(); - nvl.set_error(EINVAL); + nvl.set_error(std::errc::invalid_argument); ATF_REQUIRE_THROW(bsd::nv_error_state, nvl.add_string_range(key, values)); } @@ -1095,7 +1097,7 @@ TEST_CASE(nvxx_add_nvlist_error) auto value = bsd::nv_list{}; auto nvl = bsd::nv_list{}; - nvl.set_error(EINVAL); + nvl.set_error(std::errc::invalid_argument); ATF_REQUIRE_THROW(bsd::nv_error_state, nvl.add_nvlist(key, value)); } @@ -1227,7 +1229,7 @@ TEST_CASE(nvxx_add_nvlist_array_error) auto value = std::vector{bsd::nv_list{}, bsd::nv_list{}}; auto nvl = bsd::nv_list(); - nvl.set_error(EINVAL); + nvl.set_error(std::errc::invalid_argument); ATF_REQUIRE_THROW(bsd::nv_error_state, nvl.add_nvlist_array(key, value)); } @@ -1340,7 +1342,7 @@ TEST_CASE(nvxx_add_descriptor_error) auto key = "test_descriptor"sv; auto nvl = bsd::nv_list{}; - nvl.set_error(EINVAL); + nvl.set_error(std::errc::invalid_argument); ATF_REQUIRE_THROW(bsd::nv_error_state, nvl.add_descriptor(key, 0)); } @@ -1454,7 +1456,7 @@ TEST_CASE(nvxx_add_binary_error) auto value = std::array<std::byte, 16>{}; auto nvl = bsd::nv_list(); - nvl.set_error(EINVAL); + nvl.set_error(std::errc::invalid_argument); ATF_REQUIRE_THROW(bsd::nv_error_state, nvl.add_binary(key, value)); } |
