Skip to content
Merged
Changes from all commits
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
7 changes: 6 additions & 1 deletion MacroCacheCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ def fetch_macros(self):
self.retrieve_macros_from_wiki()
print("Downloading icons...")
for macro in self.macros.values():
self.get_icon(macro)
try:
self.get_icon(macro)
except RuntimeError as e:
self.macro_errors[macro.name] = str(e)
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The new RuntimeError handler can overwrite a more specific existing entry for this macro in self.macro_errors (e.g., if get_icon already recorded a message before raising). Consider only setting this key when it’s not already present, or preserving/combining the existing message so the root cause isn’t lost.

Suggested change
self.macro_errors[macro.name] = str(e)
new_msg = str(e)
existing_msg = self.macro_errors.get(macro.name)
if existing_msg is None:
self.macro_errors[macro.name] = new_msg
elif new_msg and new_msg not in existing_msg:
self.macro_errors[macro.name] = f"{existing_msg} | {new_msg}"

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

If get_icon raises, this handler records an error but leaves macro.icon/macro.icon_data in whatever partial state they were in at the time of the exception. To keep the cache consistent with the other error paths in get_icon (which clear macro.icon on failure), consider resetting the macro’s icon fields here as well.

Suggested change
self.macro_errors[macro.name] = str(e)
self.macro_errors[macro.name] = str(e)
# Ensure macro icon fields are consistent with other error paths in get_icon
macro.icon = None
macro.icon_data = None

Copilot uses AI. Check for mistakes.
self.macro_stats["errors"] = len(self.macro_errors)

def create_cache(self) -> str:
Expand Down Expand Up @@ -167,6 +170,8 @@ def get_icon(self, macro: Macro):
"""Downloads the macro's icon from whatever source is specified and stores its binary
contents in self.icon_data"""
if macro.icon.startswith("http://") or macro.icon.startswith("https://"):
if "freecadweb" in macro.icon:
macro.icon = macro.icon.replace("freecadweb", "freecad")
parsed_url = urllib.parse.urlparse(macro.icon)
Comment on lines 172 to 175
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

These changes introduce new behaviors that aren’t covered by the existing TestMacroCatalog suite (1) continuing fetch_macros() when get_icon() raises, and (2) translating freecadwebfreecad in icon URLs. Adding a unit test that mocks requests.get / MacroCatalog.get_icon would help prevent regressions (e.g., ensuring other macros still get processed and the translated URL is requested).

Copilot uses AI. Check for mistakes.
try:
p = requests.get(macro.icon, headers=headers, timeout=10.0)
Expand Down
Loading