Skip to content

Commit a2e10e1

Browse files
github-actions[bot]johnkerlteo-tsirpanis
authored
[Backport release-2.27] Show reasons a POSIX file cannot be read (#5432) (#5433)
Backport of #5432 to release-2.27 --- TYPE: IMPROVEMENT DESC: Show reasons a POSIX file cannot be read --------- Co-authored-by: John Kerl <[email protected]> Co-authored-by: Theodore Tsirpanis <[email protected]>
1 parent d02ef8f commit a2e10e1

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

tiledb/sm/filesystem/mem_filesystem.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,12 @@ class MemFilesystem::File : public MemFilesystem::FSNode {
183183
assert(buffer);
184184

185185
if (offset + nbytes > size_)
186-
return LOG_STATUS(
187-
Status_MemFSError("Cannot read from file; Read exceeds file size"));
186+
return LOG_STATUS(Status_MemFSError(fmt::format(
187+
"Cannot read from file; Read exceeds file size: offset {} nbytes {} "
188+
"size_ {}",
189+
offset,
190+
nbytes,
191+
size_)));
188192

189193
memcpy(buffer, (char*)data_ + offset, nbytes);
190194
return Status::Ok();

tiledb/sm/filesystem/posix.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,15 @@ void Posix::read(
273273
auto path = uri.to_path();
274274
uint64_t file_size;
275275
this->file_size(URI(path), &file_size);
276-
if (offset + nbytes > file_size)
277-
throw IOError("Cannot read from file; Read exceeds file size");
276+
if (offset + nbytes > file_size) {
277+
throw IOError(fmt::format(
278+
"Cannot read from file; Read exceeds file size: offset {}, nbytes {}, "
279+
"file_size {}, URI {}",
280+
offset,
281+
nbytes,
282+
file_size,
283+
uri.to_path()));
284+
}
278285

279286
// Open file
280287
int fd = open(path.c_str(), O_RDONLY);

tiledb/sm/filesystem/win.cc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
#include "uri.h"
5959
#include "win.h"
6060

61+
#include <fmt/format.h>
62+
6163
using namespace tiledb::common;
6264
using tiledb::common::filesystem::directory_entry;
6365

@@ -462,11 +464,23 @@ Status Win::read(
462464
0) {
463465
auto gle = GetLastError();
464466
CloseHandle(file_h);
465-
return LOG_STATUS(Status_IOError(
466-
"Cannot read from file '" + path + "'; File read error " +
467-
(gle != 0 ? get_last_error_msg(gle, "ReadFile") :
468-
"num_bytes_read " + std::to_string(num_bytes_read) +
469-
" != nbyes " + std::to_string(nbytes))));
467+
468+
std::string err_msg;
469+
if (gle != 0) {
470+
err_msg = get_last_error_msg(gle, "ReadFile");
471+
} else {
472+
err_msg = std::string("num_bytes_read ") +
473+
std::to_string(num_bytes_read) + " != nbytes " +
474+
std::to_string(nbytes);
475+
}
476+
477+
return LOG_STATUS(Status_IOError(fmt::format(
478+
"Cannot read from file '{}'; File read error '{}' offset {} nbytes "
479+
"{}",
480+
path,
481+
err_msg,
482+
offset,
483+
nbytes)));
470484
}
471485
byte_buffer += num_bytes_read;
472486
offset += num_bytes_read;

0 commit comments

Comments
 (0)