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

Conversation

prernadh
Copy link
Contributor

@prernadh prernadh commented Dec 4, 2024

What changes are proposed in this pull request?

Loading brain results can error out and the error tends to be hidden with the current logging level and exception handling. This PR addresses both these issues.

How is this patch tested? If it is not, please explain why.

Not tested as its a logging update.

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling and logging for configuration and results loading, providing clearer context for failures.
  • Chores

    • Enhanced logging to capture specific exception details, aiding in debugging and maintenance.

Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

Walkthrough

The changes primarily involve enhancing error handling and logging within the BaseRunConfig and BaseRunResults classes in the fiftyone/core/runs.py file. The from_dict method in both classes has been updated to replace generic exception handling with specific exception logging. This allows for more informative log messages that include exception details and the class name, improving the clarity and traceability of errors during configuration and result loading.

Changes

File Path Change Summary
fiftyone/core/runs.py Updated from_dict method in BaseRunConfig and BaseRunResults to improve error handling and logging. Specific exceptions are now logged with detailed messages including class names and error reasons.

Poem

In the code where errors play,
A rabbit hops to save the day.
With logs that tell of troubles near,
Clarity brings us all good cheer.
So let us code with joy and glee,
For every bug's a chance to see! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@prernadh prernadh requested a review from brimoor December 4, 2024 17:58
@prernadh prernadh marked this pull request as ready for review December 4, 2024 17:58
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
fiftyone/core/runs.py (1)

138-140: LGTM! Enhanced error handling and logging.

The changes improve error visibility by:

  1. Capturing and logging specific exception details
  2. Upgrading log level from debug to warning for better visibility
  3. Including both the class name and error reason in the message

Consider using string formatting with parentheses for better readability:

-                f"Unable to load {config_cls} due to {e}; falling back to base class"
+                f"Unable to load {config_cls} (reason: {e}); falling back to base class"
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a31a55a and 13903a1.

📒 Files selected for processing (1)
  • fiftyone/core/runs.py (1 hunks)

@prernadh prernadh requested a review from ehofesmann December 4, 2024 18:15
Copy link
Contributor

@benjaminpkane benjaminpkane left a comment

Choose a reason for hiding this comment

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

LGTM

@prernadh prernadh force-pushed the prerna/update-base-run-error-handling branch from 13903a1 to 8929baa Compare December 13, 2024 06:08
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
fiftyone/core/runs.py (1)

Line range hint 1-1024: Consider standardizing error handling patterns

The codebase would benefit from a more consistent error handling strategy:

  1. Standardize when to use debug vs warning log levels
  2. Consider adding version checks consistently where appropriate
  3. Establish a pattern for including exception details in log messages

Consider creating an error handling utility module that provides:

  • Standardized logging functions with consistent formatting
  • Version compatibility checks
  • Exception type categorization
    This would improve maintainability and ensure consistent error reporting across the codebase.
🧰 Tools
🪛 Ruff (0.8.2)

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

Remove assignment to unused variable e

(F841)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13903a1 and 8929baa.

📒 Files selected for processing (1)
  • fiftyone/core/runs.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
fiftyone/core/runs.py

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

Remove assignment to unused variable e

(F841)

Comment on lines +138 to +141
except Exception as e:
logger.warning(
f"Unable to load {config_cls}; falling back to base class",
exc_info=True,
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)

@prernadh prernadh merged commit b2734ab into develop Dec 13, 2024
14 checks passed
@prernadh prernadh deleted the prerna/update-base-run-error-handling branch December 13, 2024 20:57
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