Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-2.27] Show reasons a POSIX file cannot be read (#5432) #5433

Open
wants to merge 5 commits into
base: release-2.27
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions tiledb/sm/filesystem/mem_filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ class MemFilesystem::File : public MemFilesystem::FSNode {
assert(buffer);

if (offset + nbytes > size_)
return LOG_STATUS(
Status_MemFSError("Cannot read from file; Read exceeds file size"));
return LOG_STATUS(Status_MemFSError(fmt::format(
"Cannot read from file; Read exceeds file size: offset {} nbytes {} "
"size_ {}",
offset,
nbytes,
size_)));

memcpy(buffer, (char*)data_ + offset, nbytes);
return Status::Ok();
Expand Down
11 changes: 9 additions & 2 deletions tiledb/sm/filesystem/posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,15 @@ void Posix::read(
auto path = uri.to_path();
uint64_t file_size;
this->file_size(URI(path), &file_size);
if (offset + nbytes > file_size)
throw IOError("Cannot read from file; Read exceeds file size");
if (offset + nbytes > file_size) {
throw IOError(fmt::format(
"Cannot read from file; Read exceeds file size: offset {}, nbytes {}, "
"file_size {}, URI {}",
offset,
nbytes,
file_size,
uri.to_path()));
}

// Open file
int fd = open(path.c_str(), O_RDONLY);
Expand Down
24 changes: 19 additions & 5 deletions tiledb/sm/filesystem/win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#include "uri.h"
#include "win.h"

#include <fmt/format.h>

using namespace tiledb::common;
using tiledb::common::filesystem::directory_entry;

Expand Down Expand Up @@ -462,11 +464,23 @@ Status Win::read(
0) {
auto gle = GetLastError();
CloseHandle(file_h);
return LOG_STATUS(Status_IOError(
"Cannot read from file '" + path + "'; File read error " +
(gle != 0 ? get_last_error_msg(gle, "ReadFile") :
"num_bytes_read " + std::to_string(num_bytes_read) +
" != nbyes " + std::to_string(nbytes))));

std::string err_msg;
if (gle != 0) {
err_msg = get_last_error_msg(gle, "ReadFile");
} else {
err_msg = std::string("num_bytes_read ") +
std::to_string(num_bytes_read) + " != nbytes " +
std::to_string(nbytes);
}

return LOG_STATUS(Status_IOError(fmt::format(
"Cannot read from file '{}'; File read error '{}' offset {} nbytes "
"{}",
path,
err_msg,
offset,
nbytes)));
}
byte_buffer += num_bytes_read;
offset += num_bytes_read;
Expand Down
Loading