Skip to content

Add retry logic when fetching addons, and save error to cache for user investigation - #493

Open
MarcBresson wants to merge 4 commits into
FreeCAD:devfrom
MarcBresson:dev
Open

Add retry logic when fetching addons, and save error to cache for user investigation#493
MarcBresson wants to merge 4 commits into
FreeCAD:devfrom
MarcBresson:dev

Conversation

@MarcBresson

@MarcBresson MarcBresson commented Sep 3, 2026

Copy link
Copy Markdown

caching errors also allows for failed add-on fetches to be retried first

Mitigates #491

MarcBresson and others added 3 commits September 3, 2026 13:29
A crash during the 6-hourly cache rebuild could permanently drop an addon's cached package.xml/icon for that cycle (since the existing good clone was deleted beforehand). Retry git commands a few times before giving up. If an update ultimately fails, keep the existing good clone. Also retry addons that failed on the previous run first, so a rate-limit-driven failure doesn't always strand the same addons at the tail of a fixed processing order.
@MarcBresson

Copy link
Copy Markdown
Author

sorry for the format issue, ruff is runing when I save files, and it seems like I forgot to undo changes from the test file

@MarcBresson

Copy link
Copy Markdown
Author

Initially I also added an extra step that tried recloning the repo when there was a fetch failure, but I figured it would be redundant so I removed it in the third commit

Comment thread AddonCatalogCacheCreator.py Outdated
Comment on lines +568 to +578
def clone_with_retries(self, url: str, branch: str, target_dir: str) -> None:
"""Attempt a shallow 'git clone' of url/branch into target_dir, retrying up to
MAX_ATTEMPTS times with a short delay in between. A timeout and a non-zero exit code
are treated identically: git's exit code doesn't reliably distinguish a transient
network blip from a permanent error, and retrying a permanent failure a couple of extra
times is cheap for an unattended job. Before every attempt, any pre-existing target_dir
is removed, since git clone refuses to run into a non-empty directory and a partial
checkout can be left behind by a killed or timed-out previous attempt. Raises
RuntimeError (with git's own stderr appended, if any was captured) if every attempt
fails; deliberately does not touch self.clone_errors, since callers use this helper for
two different targets that need different keys."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to spell out in a comment the exact implementation details: in general I try to limit docstrings to a sentence or two. At some point it's easier to just read the code!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I simplified docstrings to be shorter :) I tried explaining what was considered an error (especially when dealing with subprocesses), and some git behaviours. I'm leaving that to the code and developer's knowledge!

@MarcBresson

Copy link
Copy Markdown
Author

also, I did not use logger because the file was using print statements, but I don't know if there is a specific internal policy against the use of logger. If you want, I can replace prints with logger calls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants