Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions be/src/io/fs/err_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,36 +78,38 @@ std::string glob_err_to_str(int code) {
}

Status localfs_error(const std::error_code& ec, std::string_view msg) {
auto message = fmt::format("{}: {}", msg, ec.message());
if (ec == std::errc::io_error) {
return Status::Error<IO_ERROR, false>(msg);
return Status::Error<IO_ERROR, false>(message);
} else if (ec == std::errc::no_such_file_or_directory) {
return Status::Error<NOT_FOUND, false>(msg);
return Status::Error<NOT_FOUND, false>(message);
} else if (ec == std::errc::file_exists) {
return Status::Error<ALREADY_EXIST, false>(msg);
return Status::Error<ALREADY_EXIST, false>(message);
} else if (ec == std::errc::no_space_on_device) {
return Status::Error<DISK_REACH_CAPACITY_LIMIT, false>(msg);
return Status::Error<DISK_REACH_CAPACITY_LIMIT, false>(message);
} else if (ec == std::errc::permission_denied) {
return Status::Error<PERMISSION_DENIED, false>(msg);
return Status::Error<PERMISSION_DENIED, false>(message);
} else {
return Status::Error<ErrorCode::INTERNAL_ERROR, false>("{}: {}", msg, ec.message());
return Status::Error<ErrorCode::INTERNAL_ERROR, false>(message);
}
}

Status localfs_error(int posix_errno, std::string_view msg) {
char buf[1024];
auto message = fmt::format("{}: {}", msg, strerror_r(errno, buf, 1024));
switch (posix_errno) {
case EIO:
return Status::Error<IO_ERROR, false>(msg);
return Status::Error<IO_ERROR, false>(message);
case ENOENT:
return Status::Error<NOT_FOUND, false>(msg);
return Status::Error<NOT_FOUND, false>(message);
case EEXIST:
return Status::Error<ALREADY_EXIST, false>(msg);
return Status::Error<ALREADY_EXIST, false>(message);
case ENOSPC:
return Status::Error<DISK_REACH_CAPACITY_LIMIT, false>(msg);
return Status::Error<DISK_REACH_CAPACITY_LIMIT, false>(message);
case EACCES:
return Status::Error<PERMISSION_DENIED, false>(msg);
return Status::Error<PERMISSION_DENIED, false>(message);
default:
return Status::Error<ErrorCode::INTERNAL_ERROR, false>("{}: {}", msg,
std::strerror(posix_errno));
return Status::Error<ErrorCode::INTERNAL_ERROR, false>(message);
}
}

Expand Down
1 change: 1 addition & 0 deletions be/src/io/fs/err_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace io {

std::string errno_to_str();
std::string errcode_to_str(const std::error_code& ec);
int error_code_to_errno(const std::error_code& ec);
std::string hdfs_error();
std::string glob_err_to_str(int code);

Expand Down
Loading