Skip to content

Commit dd8285f

Browse files
ArthapzMorganCaron
authored andcommitted
fix expectNoError which wasn't returning a value on happy path
1 parent 2bfbbd0 commit dd8285f

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

modules/System/Error.mpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ export namespace CppUtils::System
4747

4848
[[nodiscard]] inline auto expectNoError(int value, std::string_view message = "") -> std::expected<int, std::runtime_error>
4949
{
50-
if (value != 0) [[unlikely]]
51-
return std::unexpected(std::runtime_error{
52-
std::empty(message) ?
53-
std::format("{}", GetLastError()) :
54-
std::format("{}: {}", message, GetLastError())});
50+
if (value == 0) [[likely]]
51+
return value;
52+
53+
return std::unexpected(std::runtime_error{
54+
std::empty(message) ?
55+
std::format("{}", GetLastError()) :
56+
std::format("{}: {}", message, GetLastError())});
5557
}
5658
#endif
5759
}

0 commit comments

Comments
 (0)