Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capturing error in loading a specific config class better and bumping log level #5213

Merged
merged 2 commits into from
Dec 13, 2024
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: 4 additions & 3 deletions fiftyone/core/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ def from_dict(cls, d):

try:
config_cls = etau.get_class(config_cls)
except:
logger.debug(
"Unable to load '%s'; falling back to base class", config_cls
except Exception as e:
logger.warning(
f"Unable to load {config_cls}; falling back to base class",
exc_info=True,
Comment on lines +138 to +141
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance exception handling and logging

The current exception handling could be improved in several ways:

  1. The caught exception is not used in the log message
  2. The catch block uses a broad Exception type
  3. The warning message could be more informative

Consider applying this improvement:

-        except Exception as e:
+        except (ImportError, AttributeError) as e:
             logger.warning(
-                f"Unable to load {config_cls}; falling back to base class",
+                f"Unable to load {config_cls}; falling back to base class. Error: {str(e)}",
                 exc_info=True,
             )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
except Exception as e:
logger.warning(
f"Unable to load {config_cls}; falling back to base class",
exc_info=True,
except (ImportError, AttributeError) as e:
logger.warning(
f"Unable to load {config_cls}; falling back to base class. Error: {str(e)}",
exc_info=True,
🧰 Tools
🪛 Ruff (0.8.2)

138-138: Local variable e is assigned to but never used

Remove assignment to unused variable e

(F841)

)
config_cls = cls.base_config_cls(type)

Expand Down
Loading