Skip to content

Commit 9a57da9

Browse files
authored
Improve Zip File Error Handling with Instructions (#620)
This PR improves the error handling for zip file operations in the code. Specifically, it addresses issues related to: - `BadZipFile` errors, which occur when the downloaded file is corrupted or not a valid .zip file. - `FileNotFoundError` for handling cases where the expected file is missing. - `RuntimeError` for catching any unexpected errors during file operations. Each exception now includes a message that directs users to report the issue at https://www.github.com/kaggle/kaggle-api. This enhancement ensures better error reporting and guides users on how to proceed when encountering problems. Linked Issue: #619
1 parent d2534a2 commit 9a57da9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

kaggle/api/kaggle_api_extended.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,8 +1536,16 @@ def dataset_download_files(self,
15361536
z.extractall(effective_path)
15371537
except zipfile.BadZipFile as e:
15381538
raise ValueError(
1539-
'Bad zip file, please report on '
1540-
'www.github.com/kaggle/kaggle-api', e)
1539+
f"The file {outfile} is corrupted or not a valid zip file. "
1540+
"Please report this issue at https://www.github.com/kaggle/kaggle-api")
1541+
except FileNotFoundError:
1542+
raise FileNotFoundError(
1543+
f"The file {outfile} was not found. "
1544+
"Please report this issue at https://www.github.com/kaggle/kaggle-api")
1545+
except Exception as e:
1546+
raise RuntimeError(
1547+
f"An unexpected error occurred: {e}. "
1548+
"Please report this issue at https://www.github.com/kaggle/kaggle-api")
15411549

15421550
try:
15431551
os.remove(outfile)

0 commit comments

Comments
 (0)