Skip to content

Commit

Permalink
HPCC-33065 Improve the error message when failing to read an index he…
Browse files Browse the repository at this point in the history
…ader/footer

Signed-off-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday committed Dec 3, 2024
1 parent 3e17a7a commit e60997f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions system/jhtree/jhtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,9 @@ CDiskKeyIndex::CDiskKeyIndex(unsigned _iD, IFileIO *_io, const char *_name, bool
blockedIOSize = _blockedIOSize;
io.setown(_io);
KeyHdr hdr;
if (io->read(0, sizeof(hdr), &hdr) != sizeof(hdr))
throw MakeStringException(0, "Failed to read key header: file too small, could not read %u bytes", (unsigned) sizeof(hdr));
offset_t sizeRead = io->read(0, sizeof(hdr), &hdr);
if (sizeRead != sizeof(hdr))
throw MakeStringException(0, "Failed to read key header: file too small, could not read %u bytes - read %u", (unsigned) sizeof(hdr), (unsigned)sizeRead);

#ifdef _DEBUG
//In debug mode always use the trailing header if it is available to ensure that code path is tested
Expand All @@ -1233,8 +1234,11 @@ CDiskKeyIndex::CDiskKeyIndex(unsigned _iD, IFileIO *_io, const char *_name, bool
#endif
{
_WINREV(hdr.nodeSize);
if (!io->read(io->size() - hdr.nodeSize, sizeof(hdr), &hdr))
throw MakeStringException(4, "Invalid key %s: failed to read trailing key header", _name);
offset_t actualSize = io->size();
offset_t readOffset = actualSize - hdr.nodeSize;
sizeRead = io->read(readOffset, sizeof(hdr), &hdr);
if (sizeRead != sizeof(hdr))
throw MakeStringException(4, "Invalid key %s: failed to read trailing key header at offset %llu, read %u", _name, readOffset, (unsigned)sizeRead);
}
init(hdr, isTLK);
}
Expand Down
2 changes: 1 addition & 1 deletion system/jlib/jio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ extern jlib_decl size32_t checked_pread(const char * filename, int file, void *b
readNow = 0;
break;
}
throw makeErrnoExceptionV(errno, "checked_pread for file '%s'", filename);
throw makeErrnoExceptionV(errno, "checked_pread for file '%s' @%lld", filename, pos);
}
}
else if (!readNow)
Expand Down

0 comments on commit e60997f

Please sign in to comment.