Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Only remove fetched files
  • Loading branch information
spoorcc authored and ben-edna committed Apr 10, 2025
commit 7db9b3e2ad874085e64880d12523bee86c3f8186
16 changes: 15 additions & 1 deletion dfetch/project/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import pathlib
from abc import ABC, abstractmethod
from contextlib import suppress
from typing import Iterable, List, Optional, Sequence, Tuple

from halo import Halo
Expand Down Expand Up @@ -116,7 +117,20 @@ def update(self, force: bool = False) -> None:

if os.path.exists(self.local_path):
logger.debug(f"Clearing destination {self.local_path}")
safe_rm(self.local_path)

with suppress(TypeError):
metadata_files = Metadata.from_file(self.__metadata.path).files
Comment on lines +121 to +122

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexplained Error Suppression category Readability

Tell me more
What is the issue?

Silent error suppression without explaining why TypeError is expected or can be safely ignored.

Why this matters

Code maintainers will have to dig through the codebase to understand why this error is suppressed, making the code harder to understand and maintain.

Suggested change ∙ Feature Preview

Add a comment explaining the rationale:

# Suppress TypeError when metadata file is invalid or has old format without 'files' field
with suppress(TypeError):
    metadata_files = Metadata.from_file(self.__metadata.path).files

Report a problem with this comment

💬 Looking for more details? Reply to this comment to chat with Korbit.


if metadata_files:
for file in metadata_files:
full_path = os.path.join(self.local_path, file.path)
safe_rm(full_path)
parent_dir = os.path.dirname(full_path)
# remove parent if empty
if not os.listdir(parent_dir):
safe_rm(parent_dir)
else:
safe_rm(self.local_path)

with Halo(
text=f"Fetching {self.__project.name} {to_fetch}",
Expand Down