From 005c6e1665c3d8fec7196ab5a416eb9d59d2cc60 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Thu, 2 Apr 2026 22:46:32 -0400 Subject: [PATCH] common: improve logging around ISO `fread` errors (#4155) Related to https://github.com/open-goal/jak-project/issues/3979 Ideally this helps figure out why it's failing for some people (EOF, or some other error, which file, etc) Closes #3979 --- common/util/read_iso_file.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/common/util/read_iso_file.cpp b/common/util/read_iso_file.cpp index 9298008fa8..3f87a4d7e3 100644 --- a/common/util/read_iso_file.cpp +++ b/common/util/read_iso_file.cpp @@ -112,9 +112,26 @@ void unpack_entry(FILE* fp, if (fseek_64(fp, entry.offset_in_file, SEEK_SET)) { ASSERT_MSG(false, "Failed to fseek iso when unpacking"); } - if (fread(buffer.data(), buffer.size(), 1, fp) != 1) { - ASSERT_MSG(false, "Failed to fread iso when unpacking"); + + // https://github.com/open-goal/jak-project/issues/3979 + // some people rarely get errors here, instead of trying to do a single fread + // let fread read in chunks so that we get a little more observability (see how many bytes it + // _can_ read) + // + // additionally, try to log the actual error + const auto bytes_read = fread(buffer.data(), 1, buffer.size(), fp); + if (bytes_read != buffer.size()) { + lg::error("did not read {} bytes, only read {}, in entry: {}", buffer.size(), bytes_read, + patched_name); + if (feof(fp)) { + lg::error("reached end of file before reading all expected bytes"); + } + if (ferror(fp)) { + lg::error("generic error reading from file"); + } + ASSERT_MSG(false, "Failed to fread iso entry when unpacking"); } + file_util::write_binary_file(path_to_entry.string(), buffer.data(), buffer.size()); iso.files_extracted++; if (iso.shouldHash) {