Skip to content

catch a logging exception #133

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

Merged
merged 2 commits into from
Apr 10, 2025
Merged

catch a logging exception #133

merged 2 commits into from
Apr 10, 2025

Conversation

misrasaurabh1
Copy link
Contributor

@misrasaurabh1 misrasaurabh1 commented Apr 10, 2025

User description

printing can also fail..


PR Type

  • Bug fix

Description

  • Wrap logger.debug call in try/except block

  • Catch and log exceptions during logging

  • Prevent failures from logging errors


Changes walkthrough 📝

Relevant files
Bug fix
equivalence.py
Wrap logger.debug with try/except for error handling         

codeflash/verification/equivalence.py

  • Added try/except around logger.debug call
  • Catches exception and logs error if logging fails
  • Enhances robustness of test result comparison
  • +18/-15 

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:47 — with GitHub Actions Failure
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:47 — with GitHub Actions Failure
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:47 — with GitHub Actions Failure
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:47 — with GitHub Actions Failure
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:47 — with GitHub Actions Failure
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:47 — with GitHub Actions Failure
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:47 — with GitHub Actions Failure
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:47 — with GitHub Actions Error
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:48 — with GitHub Actions Failure
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:48 — with GitHub Actions Failure
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:48 — with GitHub Actions Failure
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:48 — with GitHub Actions Failure
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:48 — with GitHub Actions Failure
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:48 — with GitHub Actions Failure
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:48 — with GitHub Actions Failure
    @misrasaurabh1 misrasaurabh1 had a problem deploying to external-trusted-contributors April 10, 2025 00:48 — with GitHub Actions Error
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Logging Exception Handling

    In the new try/except block wrapping the logger.debug call, consider enhancing error reporting by logging additional context or a stack trace. This can help with debugging if logging fails.

    try:
        logger.debug(
            "File Name: %s\n"
            "Test Type: %s\n"
            "Verification Type: %s\n"
            "Invocation ID: %s\n"
            "Original return value: %s\n"
            "Candidate return value: %s\n"
            "-------------------",
            original_test_result.file_name,
            original_test_result.test_type,
            original_test_result.verification_type,
            original_test_result.id,
            original_test_result.return_value,
            cdd_test_result.return_value,
        )
    except Exception as e:
        logger.error(e)
    break

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Improve exception logging

    Replace logger.error(e) with logger.exception to automatically include the stack
    trace and improve error diagnostics.

    codeflash/verification/equivalence.py [48-65]

     try:
         logger.debug(
             "File Name: %s\n"
             "Test Type: %s\n"
             "Verification Type: %s\n"
             "Invocation ID: %s\n"
             "Original return value: %s\n"
             "Candidate return value: %s\n"
             "-------------------",
             original_test_result.file_name,
             original_test_result.test_type,
             original_test_result.verification_type,
             original_test_result.id,
             original_test_result.return_value,
             cdd_test_result.return_value,
         )
     except Exception as e:
    -    logger.error(e)
    +    logger.exception("Logging test result details failed")
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion correctly improves error diagnostics by replacing logger.error with logger.exception, which automatically logs the traceback. However, it addresses a minor enhancement in error handling, leading to a moderate impact on the overall code quality.

    Medium

    @misrasaurabh1 misrasaurabh1 merged commit 1fc1ccf into main Apr 10, 2025
    7 of 15 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants