Skip to content

Commit

Permalink
Show reasons a POSIX file cannot be read
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Jan 23, 2025
1 parent efd3a21 commit b3dfca0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 7 additions & 2 deletions tiledb/sm/filesystem/mem_filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/

#include <algorithm>
#include <format>
#include <mutex>
#include <sstream>
#include <unordered_set>
Expand Down Expand Up @@ -183,8 +184,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(std::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
14 changes: 11 additions & 3 deletions tiledb/sm/filesystem/posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@

#ifndef _WIN32

#include "tiledb/sm/filesystem/posix.h"
#include "tiledb/common/filesystem/directory_entry.h"
#include "tiledb/common/logger.h"
#include "tiledb/common/stdx_string.h"
#include "tiledb/sm/filesystem/posix.h"
#include "tiledb/sm/misc/constants.h"
#include "tiledb/sm/misc/tdb_math.h"
#include "uri.h"
Expand All @@ -47,6 +47,7 @@
#include <unistd.h>

#include <algorithm>
#include <format>
#include <fstream>
#include <future>
#include <iostream>
Expand Down Expand Up @@ -273,8 +274,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(std::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

0 comments on commit b3dfca0

Please sign in to comment.