Skip to content

Commit

Permalink
CUDF_EXPECTS instead of ifs
Browse files Browse the repository at this point in the history
  • Loading branch information
vuule committed Jan 4, 2024
1 parent 4800fd5 commit b5b933b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cpp/src/io/utilities/file_io_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ namespace detail {
auto const err = errno;

if (auto const path = std::filesystem::path(filepath); is_create) {
if (not std::filesystem::exists(path.parent_path())) {
CUDF_FAIL("Cannot create output file; directory does not exist");
}
} else if (not std::filesystem::exists(path)) {
CUDF_FAIL("Cannot open file; it does not exist");
CUDF_EXPECTS(std::filesystem::exists(path.parent_path()),
"Cannot create output file; directory does not exist");

} else {
CUDF_EXPECTS(std::filesystem::exists(path), "Cannot open file; it does not exist");
}

std::array<char, 1024> error_msg_buffer;
auto const error_msg = strerror_r(err, error_msg_buffer.data(), 1024);
CUDF_FAIL("Cannot open file; failed with errno " + std::string{error_msg});
CUDF_FAIL("Cannot open file; failed with errno: " + std::string{error_msg});
}

[[nodiscard]] int open_file_checked(std::string const& filepath, int flags, mode_t mode)
Expand Down

0 comments on commit b5b933b

Please sign in to comment.