Cherry-picked from #47918 Co-authored-by: Kaijie Chen <chenkaijie@selectdb.com>
This commit is contained in:
committed by
GitHub
parent
dd86f9db6c
commit
c099ccdbd0
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user