Skip to content

Commit 0456b23

Browse files
xuhancnpytorchmergebot
authored andcommitted
[AOTI] Add verbose error information for extract file (pytorch#163718)
This PR optimize `extract_file` functions: 1. `normalize_path_separator` the dest path for Windows. 2. Add verbose error message: a. On Linux, add mz_zip error string. b. On Windows, add mz_zip error string and Windows error code. For the UT `test_package_user_managed_weight`: <img width="1910" height="442" alt="image" src="https://github.com/user-attachments/assets/6a63eda1-70ce-40fb-9681-adc955463884" /> It still have issue with error code `32`, checked https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499- and find the verbose is `ERROR_SHARING_VIOLATION`. It is a little complex to debug, I will continue to working on it in further PR. Pull Request resolved: pytorch#163718 Approved by: https://github.com/desertfire
1 parent c414f75 commit 0456b23

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

torch/csrc/inductor/aoti_package/model_package_loader.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace fs = std::filesystem;
2424

2525
// TODO: C++17 has the filesystem header, which may replace these
2626
#ifdef _WIN32
27+
#include <Windows.h>
2728
// On Windows, the POSIX implementations are considered deprecated. We simply
2829
// map to the newer variant.
2930
#include <direct.h>
@@ -541,12 +542,28 @@ class RAIIMinizArchive {
541542
void extract_file(
542543
const std::string& zip_filename,
543544
const std::string& dest_filename) {
545+
// Can't normalize_path_separator zip_filename, as it is zip index.
546+
std::string path_dest_filename = normalize_path_separator(dest_filename);
544547
if (!mz_zip_reader_extract_file_to_file(
545-
&_zip_archive, zip_filename.c_str(), dest_filename.c_str(), 0)) {
548+
&_zip_archive,
549+
zip_filename.c_str(),
550+
path_dest_filename.c_str(),
551+
0)) {
552+
#ifdef _WIN32
553+
DWORD dwErrCode = GetLastError();
546554
throw std::runtime_error(fmt::format(
547-
"Failed to extract zip file {} to destination file {}",
555+
"Failed to extract zip file {} to destination file {}, error code: {}, mz_zip error string: {}",
548556
zip_filename,
549-
dest_filename));
557+
path_dest_filename,
558+
dwErrCode,
559+
mz_zip_get_error_string(mz_zip_get_last_error(&_zip_archive))));
560+
#else
561+
throw std::runtime_error(fmt::format(
562+
"Failed to extract zip file {} to destination file {}, mz_zip error string: {}",
563+
zip_filename,
564+
path_dest_filename,
565+
mz_zip_get_error_string(mz_zip_get_last_error(&_zip_archive))));
566+
#endif
550567
}
551568
}
552569

0 commit comments

Comments
 (0)