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

HPCC-33065 Improve the error message when failing to read an index header/footer #19331

Merged
merged 1 commit into from
Dec 4, 2024
Merged
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
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 '%s' header: file too small, could not read %u bytes - read %u", _name, (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
Loading